-1

I downloaded and installed mysql-5.7.17-macos10.12-x86_64 ,the workbench and the mysql-connector-java-5.1.40-bin.jar . I use the the following code to coonect mysql database,but it throws the com.mysql.jdbc.exceptions.jdbc4.CommunicationsException.

Connecting to database: jdbc:mysql://127.0.0.1:3306/demo?user=root&password=root
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. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

I can use the username and password to connect the database in mysqlworkbench and the MYSQL Server Status is running.Does it matter that I have mysql of other version?The version of Mysql in use is 5.7.17.

       try {
           Class.forName("com.mysql.jdbc.Driver");
           String conn = "jdbc:mysql://" + d_server_name + "/" + 
                   d_db_name+"?user="+d_user_name+"&password="+d_password;
           System.out.println("Connecting to database: " + conn);
           d_connect = DriverManager.getConnection(conn);
           System.out.println("Connected to database");
           return d_connect;
       } catch(Exception e) {
           throw e;
       }     
Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
PuppeyD
  • 11
  • 3

1 Answers1

-1

Try with below format. connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/database","root", "root");

Mohan
  • 11
  • 4