jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l" Watch "Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l" New topic
Author

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l

Nathan Trick
Greenhorn

Joined: Jun 29, 2012
Posts: 1
I have been having trouble connecting to a MySQL database on GoDaddy on certain internet connections. It works perfectly at my house but when I go use my college's it fails and prints out the errors:

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

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
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:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:348)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2391)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2428)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
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:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Main.main(Main.java:332)
Caused by: java.net.ConnectException: Connection timed out: 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:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
... 15 more

The connection looks like this:

// Accesses the driver
Class.forName("com.mysql.jdbc.Driver");

// Connects to the database
Connection con = DriverManager.getConnection("jdbc:mysql://database.db.9507566.hostedresource.com/database","username", "password");

It fails on con.

I am using the Connector/J 5.1.20 driver and I put in the class path properly.
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
Nathan Trick wrote:I have been having trouble connecting to a MySQL database on GoDaddy on certain internet connections. It works perfectly at my house but when I go use my college's it fails and prints out the errors:
Connection con = DriverManager.getConnection("jdbc:mysql://database.db.9507566.hostedresource.com/database","username", "password");

It should be network issue. You can try to ping database.db.9507566.hostedresource.com on the failed host.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l