LoginSignup
0
1

More than 5 years have passed since last update.

MySQL接続でのエラー CommunicationsException: Communications link failure

Posted at

HTTP通信を用いてAndroidアプリからサーバのMySQLへの接続を試みたところ以下のエラーが発生しました。

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.

別のPC端末からデータベースへのアクセスと、データベースがあるIPアドレスへAndroid側からpingが通っていることは確認済みです。

回答お願いします。
以下ソースです。

//接続
public String connect() {
  Connection con;      //接続オブジェクト
    String test = "OK";
    try{
        String URL = "jdbc:mysql://'宛先IP'/'database名'";
        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();
}
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1