-
How to connect to an MySQL database on a remote server using Java?
What I want to do is to connect to an MySQL database on a remote server. The following is my code.
Connection con;
Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
con = DriverManager.getConnection("jdbc:mysql://remoteserver:3306/mydatabase", "root", "password");
I got com.mysql.jdbc.CommunicationsException. The following is the stack trace.
java.net.SocketException: java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:156)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2555)
at com.mysql.jdbc.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager .java:525)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
Can somebody please tell me how to correct this error?
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|