[JAVA] Errors on MySQL connection CommunicationsException: Communications link failure

When I tried to connect to MySQL on the server from the Android app using HTTP communication, the following error occurred.

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.

It has been confirmed that access to the database from another PC terminal and ping from the Android side to the IP address where the database is located.

Answer please. Below is the source.

//接続 public String connect() { Connection con; // Connection object String test = "OK"; try{ String URL = "jdbc: mysql: //'destination IP'/'database name'"; String USERNAME = "user"; String PASSWORD = "password";

        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(URL,USERNAME,PASSWORD);
    }
    catch (Exception e){
        test = ""+e;
        //Toast toast = Toast.makeText(activity,"ERROR!"+e,Toast.LENGTH_LONG);
    }
    return test;
}

//接続のクローズ public void close(){ con.close(); }

Recommended Posts

Errors on MySQL connection CommunicationsException: Communications link failure
MySql connection error