Mój problem wygląda następująco: staram się połączyć z bazą danych mysql za pośrednictwem javy i jdbc. Kod wygląda tak:
public class MySQLConnection {
Connection con = null;
Statement st = null;
ResultSet rs = null;
final String url = "jdbc:mysql://mysql.cba.pl:3306/xxx";
final String driver = "com.mysql.jdbc.Driver";
final String user = "xxx";
final String pass = "xxx";
public MySQLConnection() {
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, pass);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if(rs.next()) {
System.out.println(rs.getString(1));
}
} catch(Exception e) {
System.out.println(e.getMessage());
} finally {
close();
}
}
private void close() {
try {
if(rs != null) {
rs.close();
}
if(st != null) {
st.close();
}
if(con != null) {
con.close();
}
} catch(SQLException e) {
System.out.println(e.getMessage());
}
}
}
Po dość długim czasie dostaję błąd:
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.
Czy robię błąd w url? Całość robię na podstawie pewnego tutoriala, dziwie się, że nie działa, może to wina tego darmowego hostingu?. Po założeniu bazy lokalnie i zmianie url na:
final String url = "jdbc:mysql://localhost:3306/xxx";
Program działa jak powinien.