1

I have just created a free sql database(http://www.freesqldatabase.com) to test one of my applications, but I can't connect to the database. I have already tested with a offline database and it worked. Instead of passing the URL, port and etc, I've passed the path to the .db.

I have the connector driver in lib folder.

I'm using this:

Connection conn;

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

String url = "jdbc:mysql://sql5.freesqldatabase.com:3306/" + dbName;

conn = DriverManager.getConnection(url, username, password);

conn.close();  

But I'm getting this exception:

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:983)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:339)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2252)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2285)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at javaapplication2.JavaApplication2.main(JavaApplication2.java:29)
Caused by: java.net.SocketException: Permission denied: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:214)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)
    ... 15 more
derloopkat
  • 6,232
  • 16
  • 38
  • 45
Max Fratane
  • 747
  • 1
  • 7
  • 21
  • They almost certainly don't allow external network access to the free databases. – Elliott Frisch Jun 18 '16 at 19:36
  • It costs money to actually connect. – Drew Jun 18 '16 at 19:44
  • I would be **very** wary of these guys, they're still using `MySQL_` as their preferred connection functions in PHP ([here](http://www.freesqldatabase.com/category/php/)) – Martin Jun 18 '16 at 19:51
  • 1
    @Martin here is another good laugh. Check out [Troy breaches](https://www.troyhunt.com/breaches-traders-plain-text-passwords/) and search on the phrase "the credentials in the URL " – Drew Jun 18 '16 at 19:55
  • That made me laugh out loud (in that way when you see a massive dog poop on a playground slide and you can't change it, but you just know someone's going to meet it). Cheers :-) – Martin Jun 18 '16 at 19:59
  • but I'm getting the same error with https://www.db4free.net. – Max Fratane Jun 18 '16 at 20:05
  • they all probably use a very similar deployment method. It's the free standard. – Martin Jun 18 '16 at 20:09
  • but take a look at this thread http://stackoverflow.com/questions/10438773/accessing-online-database-with-java They are doing almost the same thing. – Max Fratane Jun 18 '16 at 20:10

1 Answers1

1

It is -as others alluded to - a firewall issue on the server end. The port 3306 is likely not open. You should be careful about (i.e. do not) putting any confidential information in a web-accessible DB like that.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560