1

I know that this issue has been discussed a lot of times but I cannot establish a connection between my Java app and MySQL server.

I'm using code form tutorials:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCTest{
  private Connection conn = null;
  public void connect(){
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      System.out.println("test");
      conn = DriverManager.getConnection("jdbc:mysql://mysql.***.***.**:3306/******","*******","top_secret_password");
      System.out.println("test2");


    } catch (SQLException ex) {
      // handle any errors
      System.out.println("SQLException: "   ex.getMessage());
      System.out.println("SQLState: "   ex.getSQLState());
      System.out.println("VendorError: "   ex.getErrorCode());
    }catch(Exception e){e.printStackTrace();}   
  }

}

Error that occured is:

test
SQLException: 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.
SQLState: 08S01
VendorError: 0

Have you got any ideas how fix it?

1

1 Answer 1

2

Try to provide the IP-address of the database instead of its name. Say

conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/*******","*******","top_secret_password");

and make sure that your firewall doesn' block 3306 port

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.