Remote connection to MySQL

I am trying in Java to connect remotely to a database and use the following code:

import java.io.*;

import java.lang.*;

import java.util.*;

import java.sql.*;

public class Test {

public static void main(String args[]) {

Connection con = null;

try {

Class.forName("com.mysql.jdbc.Driver").newInstance ();

con = DriverManager.getConnection("jdbc:mysql://llsti.org:3306/universalaccess?user=*****&password=****");

if(!con.isClosed())

System.out.println("Successfully connected to " +

"MySQL server using TCP/IP...");

} catch(Exception e) {

System.err.println("Exception: " + e.getMessage());

} finally {

try {

if(con != null)

con.close();

} catch(SQLException e) {}

}

}

}

But it doesnt do anything.. it compiles properly but then it just stuck in getConnection(). it doesnt print thereafter.

Any suggestion would be of great help.

Thanks,

Akhil

[1014 byte] By [akhildhanukaa] at [2007-10-3 3:30:00]
# 1

Stack Trace shows as follows:

Successfully connected to

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:2641)

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 Test.main(Test.java:14)

** END NESTED EXCEPTION **

Last packet sent to the server was 46 ms ago.

akhildhanukaa at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Is a firewall blocking access to port 3306? Just because you can ping it doesn't mean you can connect to it.Brian
brian@cubik.caa at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

No I have already created an exception in firewall to port number 3306. I have seen everything very minutely.

Plz can any one suggest me or provide me with a working code to access database remotely from any IP address. I have done all required settings in database and created an user with all GRANT options too.

Cheers!!!

Akhil

akhildhanukaa at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

It isn't possible to have working code if you don't have the required network connectivity. No amount of coding will solve that problem. Writing code is not the solution to all problems.

The stack trace you printed is pretty clear: the program can't connect to port 3306 at lsti.org. You need to change the network so it can.

DrClapa at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Hi,So what network settings I am suppose to perform? I would be really greatful for any more suggestions.Thanks for the help.Akhil
akhildhanukaa at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> Hi,

>

> So what network settings I am suppose to perform? I

> would be really greatful for any more suggestions.

>

I cannot put this really any clearer because it's been told to you before. You are getting a 2003 error. This is what the MySQL site has to say about that error.

The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, the network port you specified is the one configured on the server, and that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

Please talk to your local network administrator and/or the administrator of the MySQL database for assistance. Either the database is not listening on that port or there is a firewall blocking your access either at your end or at the server end.

This is NOT a Java problem. You cannot connect using any other tool to this database.

cotton.ma at 2007-7-14 21:23:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...