Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Unanswered: Remote connection to MySQL

    I have created a MySQL (5.0.77-community) database at a non-free webhosting service. In cPanel I created a new user with all possible privileges and added '%' as an access host. I would like to connect to this base remotely (as in not from the phpMyAdmin in cPanel). More precisely I would like to connect to this database with JDBC, but help on connecting with any remote client would be much appreciated. I did try googling for a solution but I found nothing of use.

    This is the code I use for connecting:
    Java Syntax (Toggle Plain Text)

    1.
    new org.gjt.mm.mysql.Driver();
    2.
    Connection c = DriverManager.getConnection("jdbc:mysql://"+server_ip+":3306/"+database_name, username, password);

    new org.gjt.mm.mysql.Driver(); Connection c = DriverManager.getConnection("jdbc:mysql://"+server_ip+":3306/"+database_name, username, password);

    And this is the exception I get:
    Quote:
    Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ption: Communications link failure

    Last packet sent to the server was 0 ms ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
    at com.mysql.jdbc.SQLError.createCommunicationsExcept ion(SQLError.java:1074)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2103)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:718)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connect ion.java:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:40 6)
    at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:302)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:282)
    at java.sql.DriverManager.getConnection(DriverManager .java:582)
    at java.sql.DriverManager.getConnection(DriverManager .java:185)
    at BaseObjects.NewMain.main(NewMain.java:25)
    Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:366)
    at java.net.Socket.connect(Socket.java:519)
    at java.net.Socket.connect(Socket.java:469)
    at java.net.Socket.<init>(Socket.java:366)
    at java.net.Socket.<init>(Socket.java:209)
    at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:253)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2026)
    ... 12 more
    Java Result: 1

    BTW: Accessing to a local server this way gives no errors (but unfortunately this is not an option for the final version of my project). Oh and the error is thrown by the getConnection method.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Don't you think your "non-free webhosting service" may be blocking port 3306? You could try running MySQL on a port that is not likely to be blocked, like 21 or 25.
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •