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!

MySQL -- JDBC Connection help !!!

843859Nov 6 2006 — edited Nov 7 2006
Hi everybody...Well I have MySQL Server and Java, I get the JDBC and tried this:

###########################################################
import java.sql.*;

public class JdbcE {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/test", "user", "pass");
if(!con.isClosed())
System.out.println("Successfully connected to MySQL server...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
###########################################################

And with that code all works fine...but when I change the Host from LOCALHOST to [ROUTER IP] like this:

con = DriverManager.getConnection("jdbc:mysql://182.185.145.12/test", "user", "pass");

I got this exception:

###########################################################
Exception: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

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

STACKTRACE:

java.net.SocketException: java.net.ConnectException: Connection timed out: conne
ct
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja
va: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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcE.main(JdbcE.java:11)


** END NESTED EXCEPTION **



Last packet sent to the server was 16 ms ago.
###########################################################

I don't know how to solve it...
I have a 2wire 1700HG router, maybe it would be a problem of the firewall can anyone help me to solve this problem??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2006
Added on Nov 6 2006
8 comments
569 views