aspose file tools*
The moose likes JDBC and the fly likes Error connecting on MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Error connecting on MySQL" Watch "Error connecting on MySQL" New topic
Author

Error connecting on MySQL

Fábio Rodrigues dos Santos
Greenhorn

Joined: Sep 08, 2009
Posts: 2
Hello everyone,

I've installed the MySQL (5.1.38 ) here in mine Windows Vista 64bits, added the Connector of the MySQL (mysql-connector-java-5.1.8-bin.jar) to the buildpath of my project but occured the following problem when I've try to connect with the MySQL but the following error quoted below appears:


Conectando ao banco
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2120)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:723)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:11)
at br.com.caelum.jdbc.TestaConexao.main(TestaConexao.java:10)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:335)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2043)
... 13 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
... 14 more


The class I've using to perform the connection test:





The JDK I've using is 1.6.0_02.

The port liberated on the Firewall to the MySQL is the 3306 and the password to the user root is admin as I've passed on the String of configuration of the class ConnectionFactory.

I remember when I maked this process on Windows Vista 32bits a time ago and all worked fine! Have any difference on JDK, Netbeans or MySQL on 32 bits and 64 bits OSs?

Best regards!
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Is MySQL runnning ? replace with "127.0.0.1" with localhost , if you dont have localhost entry by default.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Welcome to Javaranch Fábio,

Did you try to connect mysql manually, I mean with command prompt or through any gui client..



Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Fábio Rodrigues dos Santos
Greenhorn

Joined: Sep 08, 2009
Posts: 2
Hello Muhammad!

I've connected with the MySQL with the command prompt with no problems.

But, I've try what the Balu said of replace with 127.0.0.1 on the configuration String and worked.

Thanks to all!
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Oh good.. you are welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error connecting on MySQL