# JDBC online MySQL-DB



## Bjarki (29. Mrz 2010)

Hallo Zusammen,

ich habe folgendes Problem:

Ich versuche auf eine Online MySQL-Datenbank ( u.a. DB4Free.net ) zuzugreifen.


```
private static String DRIVER_CLASS = "com.mysql.jdbc.Driver";
private static String CONNECT_URL = "jdbc:mysql://db4free.net:3306/DBNAME";
private static String USER = "username";
private static String PWD = "pw";

public static Connection getConnection() throws ClassNotFoundException, SQLException
	  {
	    Class.forName(DRIVER_CLASS);

	    Properties prop = new Properties();
	    if (USER != null)
	      prop.setProperty("user", USER);
	    if (PWD != null)
	      prop.setProperty("password", PWD);

	    return DriverManager.getConnection(CONNECT_URL, prop);
	  }
```

Ich bekomme jedesmal folgende Fehlermeldung:



```
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(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1119)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2257)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:784)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:354)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at SQL.jdbcwebserver.getConnection(jdbcwebserver.java:61)
	at SQL.jdbcwebserver.checkConnection(jdbcwebserver.java:19)
	at SQL.jdbcwebserver.main(jdbcwebserver.java:66)
Caused by: 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(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1119)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2178)
	... 14 more
Caused by: java.net.ConnectException: Connection timed out: connect
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.PlainSocketImpl.doConnect(Unknown Source)
	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at java.net.Socket.<init>(Unknown Source)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
	... 15 more
```

Der Zugriff auf eine lokale MySQL-DB klappt ohne Probleme. Jemand eine Idee?

Grüßle

Bjarki


----------



## citizen_erased (29. Mrz 2010)

Kann sein, dass mysql auf db4free.net nur Zugriff von genau dort erlaubt. Falls Du Zugriff auf dortige mysql db hast, kannst du das in der tabelle user oder db (?) der datenbank mysql ändern. Hier steht dann was von "localhost" etc..


----------



## ARadauer (29. Mrz 2010)

versuch mal mit einem tool wie sqlyog drauf zu kommen


----------



## Bjarki (29. Mrz 2010)

Problem gefunden. Unser Admin meinte zwar die Ports seien offen, aber nach einem Versuch Zuhause funktionierts ohne Probleme. 
Ich werd ihn morgen nochmal darauf ansprechen...


----------

