I was trying to connect a Java Web application to a MySQL database. I used this code to see if the connection was okay:
public class Funciones {
public boolean communicationStatus(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/practicas","root","Contrasena1.");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("show databases;");
System.out.println("Conectado");
return true;
}
catch(Exception e){
System.out.println(e);
return false;
}
}
}
And then I get this error: 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.