Connection Timeout...
Posted by: Mario Rossi
Date: December 19, 2004 06:53AM

Hi all,

please help me because I'm frustrated. Well, I have a simple Java application that I want to connect to a MySQL DB that is on a server; this is my code:

Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://62.149.150.28:3306/my_db?user=my_user&password=my_password";
Connection conn = DriverManager.getConnection(url);

It doesn't work. This is the error stack:

java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection timed out: connect

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection timed out: connect

STACKTRACE:

java.net.ConnectException: Connection timed out: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)

at java.net.Socket.connect(Socket.java:452)

at java.net.Socket.connect(Socket.java:402)

at java.net.Socket.<init>(Socket.java:309)

at java.net.Socket.<init>(Socket.java:124)

at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)

at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)

at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)

at com.mysql.jdbc.Connection.<init>(Connection.java:450)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)

at java.sql.DriverManager.getConnection(DriverManager.java:512)

at java.sql.DriverManager.getConnection(DriverManager.java:193)

at provadatabase.mainFrame.jbInit(mainFrame.java:56)

at provadatabase.mainFrame.<init>(mainFrame.java:34)

at provadatabase.provaDatabaseMain.<init>(provaDatabaseMain.java:27)

at provadatabase.provaDatabaseMain$1.run(provaDatabaseMain.java:65)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
<


** END NESTED EXCEPTION **



at com.mysql.jdbc.Connection.createNewIO(Connection.java:1851)

at com.mysql.jdbc.Connection.<init>(Connection.java:450)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)

at java.sql.DriverManager.getConnection(DriverManager.java:512)

at java.sql.DriverManager.getConnection(DriverManager.java:193)

at provadatabase.mainFrame.jbInit(mainFrame.java:56)

at provadatabase.mainFrame.<init>(mainFrame.java:34)

at provadatabase.provaDatabaseMain.<init>(provaDatabaseMain.java:27)

at provadatabase.provaDatabaseMain$1.run(provaDatabaseMain.java:65)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

But the funny thing is that if I substitute the IP address with "localhost", it works!

Can anyone help please?

Options: ReplyQuote


Subject
Written By
Posted
Connection Timeout...
December 19, 2004 06:53AM
December 21, 2004 08:39AM
January 07, 2005 02:17PM
January 07, 2005 02:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.