5 messages in com.mysql.lists.javaRe: Problem with "access to data source"
FromSent OnAttachments
Jeremy Jenkins02 Mar 2000 00:59 
Roland Becker02 Mar 2000 01:18 
André Bjärby02 Mar 2000 01:24 
Jeremy Jenkins02 Mar 2000 03:06 
Steve Barrett02 Mar 2000 13:50 
Subject:Re: Problem with "access to data source"
From:André Bjärby (and@visionaut.se)
Date:03/02/2000 01:24:15 AM
List:com.mysql.lists.java

Jeremy Jenkins wrote:

Ok, I can load my drivers now, but I can't seem to actually connect with my local mySQL server (the ONLY thing I've done to mySQL after a fresh install is to give root a password) I've written the following test program...

import java.sql.*

public class test{ static String url="jdbc:mysql://localhost/mysql"; static String user="root"; static String pass="xxxxxx";

public static main( String args[]){ // Load JDBC Drivers try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); System.out.println("\nLoading JDBC Driver..."); } catch (Exception e){ System.err.println("\nUnable to load driver!\n"); e.printStackTrace(); } // Connect to mySQL Server try{ Connection con = DriverManager.getConnection(url, user, pass); System.out.println("Connecting to mySQL Server..."); } catch (Exception e){ System.err.println("Unable to connect to mySQL server!\n"); e.printStackTrace(); } } }

It compiles, but gives the following error upon execution...

java.sql.SQLException: Server configuration denies access to data source

at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:144) at org.gjt.mm.mysql.Connection.<init>(Connection.java:230) at org.gjt.mm.mysql.Driver.connect(Driver.java:126) at java.sql.DriverManager.getConnection(DriverManager.java:453) at java.sql.DriverManager.getConnection(DriverManager.java:133) at test.main(test.java:20)

I've read through most of the mySQL manual, paying especially close attention to Chapter 6. In section 6.15 it claims that if you can access the the correct database using the command 'mysql -u root -pxxxxxxx mysql' from the command prompt, then the error resides in the Java, not the mySQL setup. I'm able to get into the mysql database with the above command line command, but my program still pukes at me... anyone see my error, or can think of something I may have missed (I am indeed a mySQL newbie as well...)?

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.

No, the problem (feature) is that if you use the mysql client from the command prompt it defaults to using a UNIX socket to connect to the server, while the jdbc driver always uses a TCP/IP connection. If your privilege system allows connections from '@localhost' it means it allows connections from the UNIX socket and not from 127.0.0.1 (also localhost but in the TCP/IP sense) which the jbdc connections come from. So you need to 'grant all privileges on foo.* to bar@127.0.0.1 ...' to get the jbdc driver to work.

I had the same problem and the above is what I deducted from some creative use of ipchains -l, tcpdump and netstat. Since I did not read the manual to carefully, please correct me if I'm wrong.

It worked for me :)

/A