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!

Cannot connect to MySQL server on localhost:3306

843854Feb 3 2004 — edited Feb 4 2004
Allthough I can acces MySQL interactively I get the following result when connecting through JDBC:

java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)

Test class:
package various;

import java.sql.*;

public class Test {

private Connection con;
private Statement stmt;
private ResultSet rs;

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

public Test() {
System.out.println("Checking MySQL access");
try {
Class.forName("org.gjt.mm.mysql.Driver");
DriverManager.setLoginTimeout(30);
con = DriverManager.getConnection("jdbc:mysql://localhost/myDb", "myUser", "myPwd");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
System.exit(0);
}

}


netstat gives:
...
unix 3 [ ] STREAM CONNECTED 71902
unix 2 [ ] DGRAM 3606
unix 2 [ ] DGRAM 2431
unix 2 [ ] DGRAM 2020
unix 2 [ ] DGRAM 1876
unix 2 [ ] DGRAM 1313


ps -ef | grep mysqld gives:
root 425 1 0 Feb02 ? 00:00:00 /bin/sh /usr/bin/safe_mysqld user=mysql pid-file=/var/lib/mysql/mysqld.pid socket=/var/lib/mysql/mysql.sock datadir=/var/lib/mysql
mysql 456 425 0 Feb02 ? 00:00:00 /usr/sbin/mysqld basedir=/usr datadir=/var/lib/mysql user=mysql pid-file=/var/lib/mysql/mysqld.pid --skip-locking
mysql 464 456 0 Feb02 ? 00:00:01 /usr/sbin/mysqld basedir=/usr datadir=/var/lib/mysql user=mysql pid-file=/var/lib/mysql/mysqld.pid --skip-locking
mysql 465 464 0 Feb02 ? 00:00:00 /usr/sbin/mysqld basedir=/usr datadir=/var/lib/mysql user=mysql pid-file=/var/lib/mysql/mysqld.pid --skip-locking
cm 18119 12919 0 17:30 pts/4 00:00:00 grep mysqld

What's wrong? In former Suse releases it worked.

Christoph
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 3 2004
Added on Feb 3 2004
4 comments
1,318 views