Hallo,
ich möchte kontakt mit einer MySQl datenbank aufnehmen:
Jedoch bekomme ich immer den Connection Timeout fehler.
Kann ich mir aber nicht erklären:
Fehler:
ich möchte kontakt mit einer MySQl datenbank aufnehmen:
Jedoch bekomme ich immer den Connection Timeout fehler.
Kann ich mir aber nicht erklären:
Code:
import java.sql.*;
public class MySqlConnection {
public static void main(String[] tanga) {
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
// Create a connection to the database
String serverName = "phpmyadmin.gastrob.de";
String mydatabase = "gastrob_de";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "******";
String password = "******";
connection = DriverManager.getConnection(url, username, password);
}
catch (ClassNotFoundException e) {
System.out.println("Could not find the database driver.");
}
catch (SQLException e) {
System.out.println("Could not connect to the database. "+e);
}
}
}
Fehler:
Code:
Could not connect to the database. com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.ConnectException
MESSAGE: Connection timed out: connect
STACKTRACE:
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:173)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:267)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at MySqlConnection.main(MySqlConnection.java:17)
** END NESTED EXCEPTION **
Last packet sent to the server was 47 ms ago.