Problem with MySQL Connector/J
I'm using NetBeans IDE 5.5 with JDK 1.6.0 on Fedora Core 6.
When I ran "./java -version
" from the JDK_HOME, I got this message:
java version"1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
Further the "mysql --version
" command had the following output :
mysql Ver 14.12 Distrib 5.0.27,for redhat-linux-gnu (i686) using
readline 5.0
I downloaded the JDBC Connector (version 5.0) for MySQL : MySQL
Connector/J, and installed it using the instruction outlined in the
Connector/J documentation (by setting the classpath in the
$USER_HOME/.bash_profile).
I attached the jar file of the Connector/J
(mysql-connector-java-5.0.4-bin.jar) in the NetBeans project as well.
From within the NetBeans IDE, when I tried to run my Java application
which tried to connect to the mysql database, the application terminated
with the following output:
com.mysql.jdbc.CommunicationsException: Communications link failure due
to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused
STACKTRACE:
java.net.SocketException: java.net.ConnectException: Connection refused
at
com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2666)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at test.DB.ConnectDB(DB.java:37)
at test.DB.<init>(DB.java:29)
at test.Main.main(Main.java:30)
** END NESTED EXCEPTION **
But the same code runs without any problem with the Eclipse 3.2 IDE on
the same system. I added a new Java Platform to the Netbeans IDE (GNU
libgcj 4.1.1 20061011 (Red Hat 4.1.1-30)). The same program ran
successfully with the new platform set in the project property. So I
concluded that may be the problem is with the SUN JDK 1.6.0. Is there
any other way to register the driver with JDK 1.6.0 (except the method
outlined in the Connector/J documentation, i.e. setting the classpath to
the driver's jar file)?
Moreover when trying to add a persistent unit for a J2EE application,
the same error occurs while connecting to my database using the MySQL
Connector/J Driver for JDBC. I've stuck to this problem since more than
a month and I hope if some one in the forum could help me.
Thanks in advance.
Regards
Aks

