0

My code results into this error, who can help me?

My program is in Android.

ERROR

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.

FUNCTION:

public Connection getConexato() throws ClassNotFoundException, SQLException, java.sql.SQLException, InstantiationException, IllegalAccessException {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = (Connection) DriverManager.getConnection("jdbc:mysql://179.219.251.158:3306/partcatalog","root","teste123");  
    return conn;
}

Ping to machine server:

C:\Users\psysvica>ping 179.219.251.158

Disparando 179.219.251.158 com 32 bytes de dados:
Resposta de 179.219.251.158: bytes=32 tempo=53ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=39ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=82ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=43ms TTL=56

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
  • first ping the machine that your DB is located – Madura Harshana Oct 29 '13 at 11:56
  • C:\Users\psysvica>ping 179.219.251.158 Disparando 179.219.251.158 com 32 bytes de dados: Resposta de 179.219.251.158: bytes=32 tempo=53ms TTL=56 Resposta de 179.219.251.158: bytes=32 tempo=39ms TTL=56 Resposta de 179.219.251.158: bytes=32 tempo=82ms TTL=56 Resposta de 179.219.251.158: bytes=32 tempo=43ms TTL=56 – user2774657 Oct 29 '13 at 11:57
  • restart the DB and try – Madura Harshana Oct 29 '13 at 12:16
  • 1
    have a look on this example and look in to most voted answer http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql/2840358#2840358 – Madura Harshana Oct 29 '13 at 12:19

1 Answers1

0

Consider the following:

  • DB server is up or down
  • IP address of the server
  • Port number is correct or wrong

So you can verify this by ping to the database server. You might need to restart the database server if needed.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
Madura Harshana
  • 1,299
  • 8
  • 25
  • 40