1

I tried to connect my Database on my virtual Server (Debian10) with a Java program on my computer (Windows 10). I tried this:

    String url = "jdbc:mysql://xyz.de:3306/xyz? useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezon 
    e=Europe/Berlin";
    String user = "xyz";
    String password = "xyz";
    try(Connection conn = DriverManager.getConnection(url, user, 
    password)) {
    System.out.println("Successfully connected to database.");
        
    }catch(SQLException ex) {
    System.err.println(ex.getMessage());
    }

And the error ist:

   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.

I created the user with "phpMyAdmin" and I gave it all permissions. And in the hostname field, I entered a "%";) I also activated the port on the server.

Thanks for Help :)

DeliaSama
  • 11
  • 2
  • mysql databases aren't usually accessible directly from the internet for security reasons. so see if your provider doesn't support ssh and use the tunnel – nbk Oct 11 '21 at 22:35
  • You might want to check the following link. https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – joemokenela Oct 11 '21 at 22:53
  • that is ot allowed here. but there are plenty of examples https://www.it-swarm.com.de/de/java/ssh-verbindung-mit-java/969823644/ – nbk Oct 12 '21 at 07:13
  • @nbk First of all thanks for answering :) Now I've tried this https://www.journaldev.com/235/java-mysql-ssh-jsch-jdbc and I'm still getting the same error. But just the ssh connection as in your example worked :) – DeliaSama Oct 12 '21 at 12:00

0 Answers0