Hi All,
This is the first time I'm using Java to connect to my online MySQL database that is hosted by a separate web host. Following is the code in use:
(I've removed the server url, username and pass for obvious reasons. They all work when I use them in my ASP web project.)
import java.sql.*;
/**
*
* @author Siddharth Dahiya
*/
public class TWMC_Online {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Starting...");
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://tribalwars.db.4489877.hostedresource.com";
DriverManager.setLoginTimeout(100);
Connection con = DriverManager.getConnection(connectionUrl, "xxxx", "xxxx");
System.out.println("Con Done...");
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
} catch (ClassNotFoundException e) {
System.out.println("Class Not Found Exception: " + e.toString());
}
System.out.println("Quiting...");
}
}
I get the following error:
run:
Starting...
SQL Exception: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** 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:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at twmc_online.TWMC_Online.main(TWMC_Online.java:23)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
Quiting...
BUILD SUCCESSFUL (total time: 21 seconds)