Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mySQL and JDBC

2 views
Skip to first unread message

Gregory Engel

unread,
Dec 9, 1999, 3:00:00 AM12/9/99
to
Hi All

I confess to being an abolute newbie to databases. (I know java pretty
well)
I've just set up mySQL on RedHat 6.1 and written my first jdbc app.
Trouble is
that I'm having problems conecting to the server. (I can from the
command line).
The code is really incidental since it is only to test things out but
I've included it anyway.

I'm sure that it is a permission thing with mySQL but I can't really
figure out what
I should set things to. I tried creating a new user and giving them all
priviliges but it
still gives me the error. (also if run as mySQL root.)

SQLException:Server configuration denies access to data source
SQLState: 08001
VendorError: 0

I'd appreciate a quick explaination of how to set permissions so I can
learn JDBC. I don't
need anything much. Just so I can get things clicking. I'll worry about
the details of
DB admin later.

Thanks
GE

CODE

import java.lang.*;
import java.sql.*;

public class testMysql
{
testMysql()
{
try {

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

}
catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}

try {
Connection C = DriverManager.getConnection(
"jdbc:mysql://localhost/customer?user=root
password=mypassword");

Statement Stmt = C.createStatement();

ResultSet RS = Stmt.executeQuery("SELECT * FROM
current");//current is name of table

while (RS.next()) {
System.out.println(RS.getString(1));
}

}
catch (SQLException E) {
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}

}

public static void main(String args[])
{
new testMysql();
}

}

William Leeke_

unread,
Dec 9, 1999, 3:00:00 AM12/9/99
to
all,

I know almost nothing about JDBC and a little more about MySQL...

Check "who" your code is running as. i.e. html,nobody etc.
It may run just fine as your user name but not as the user that's trying
to connect to the database.

MySQL has configuration options for log files, check those settings.
Also check /var/logs/<hostname>.accessdenied or <hostname>.log

NOTE: Your permissions in MySQL don't take effect until 'mysqladmin
reload' or 'mysqladmin flush-permissions' when not using GRANT command
in the later releases.

hope this helps,

-wbl

Steve Dyrdahl

unread,
Dec 10, 1999, 3:00:00 AM12/10/99
to Gregory Engel
> I'd appreciate a quick explaination of how to set permissions so I can
> learn JDBC. I don't

Chapter 6 of the mySQL documentation gives a pretty good explanation of
the access privilege system.

http://mysql.he.net/Manual_chapter/manual_Privilege_system.html#Privilege_system

The user that you are trying to connect as needs:
1. The privilege to connect from the machine where your java application
is running. ( Localhost does not count. )
2. The privilege to select, update, etc. tables in the specific database
your application is connecting to.


Steve D.

d

unread,
Dec 15, 1999, 3:00:00 AM12/15/99
to
I too have a similar problem

I can connect from the command line, but if I call the java program that
connects to the database as user nobody, it can not find the JDBC driver to
connect to the database (Classnotfoundexception)

Darren

Steve Dyrdahl <dyr...@nixon.reticular.com> wrote in message
news:Pine.GSO.4.05.991210...@nixon.reticular.com...

d

unread,
Dec 15, 1999, 3:00:00 AM12/15/99
to

I too have a similar problem

I can connect from the command line, but if I call the java program that
connects to the database as user nobody, it can not find the JDBC driver to
connect to the database (Classnotfoundexception)

I am assuming that this is a classpath problem for user nobody?

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at java.net.URLClassLoader$1.run(Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Compiled Code)
at java.lang.ClassLoader.loadClass(Compiled Code)
at sun.misc.Launcher$AppClassLoader.loadClass(Compiled Code)
at java.lang.ClassLoader.loadClass(Compiled Code)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Compiled Code)
at StatData.getWBScore(Compiled Code)
at ChatCommandHandler.handleCommand(Compiled Code)
at ChatClient.handleInput(Compiled Code)
at ChatClient.run(Compiled Code)


0 new messages