Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

connecting to a remote mysql server

843854Jul 23 2003 — edited Jul 31 2003
Hello,
I am having a wierd problem.
I have mysql running on a server and am writing java code that uses JDBC connector J drivers to connect to it froma local machine.
However, the sqlConnection object that I obtain is null so I am not getting connected.
I created a user who can access the mysql server from anywhere by doing
GRANT ALL PRIVILEGES ON *.* TO username@"%" IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

When i use command prompt to connect with this user , then it works. So i can connect from the local machine to this remote server with the command prompt on the local machine , but the java code running on this same local machine doesn't like it.
Here is what I do:
Connection sqlConnection=null; //host is is ritika.gmr.com
String url = "jdbc:mysql//ritika.gmr.com/audio"; //database name-audio
try{
try{
Class.forName(driver).newInstance();
}
catch (Exception ioe)
{
System.out.println("unable to load drivers");
}
sqlConnection = DriverManager.getConnection(url,"username","some_pass");

}
catch (Exception E) {
System.out.println("No Connection");}
if (sqlConnection==null)
System.out.println("its null");


I alwaysget "its null" as the output.

Another strange thing is that when I logged on to the actual host machine using ssh and then tried to connect to the mysql server running on it with this same username and some_pass, it did not work. It said access denied.
Why is this because i created the username to conenct from "%". Doesn't this include localhost itself. And why does it let me connect from command prompt of my local machine.
Thanks
Please let me know whats going on.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2003
Added on Jul 23 2003
5 comments
102 views