私のアプリケーションはLinuxMandrivaで実行されており、MySQLデータベースに接続できません。
my.cnfの一部:
bind-address="127.0.0.1"
# skip- networking
私wait_timeout
は次のように設定しました:
SET GLOBAL wait_timeout = 28800;
データベースへの接続を取得しようとしています:
public class TestJdbc {
public static void main(String[] args) {
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "gibrid", userName = "java",
password = "java";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName, userName, password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
このクラスをjarにパックして、サーバーに送信しました。実行しようとすると、次のようになります。
com.mysql.jdbc.CommunicationsException:
Communications link failure due to underlying exception:
** BEGIN MESSAGE **
java.net.ConnectException
MESSAGE: Connection timed out
STACKTRACE: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:333)
...
しかし、ローカルホストからこのコードを実行すると、すべて問題ありません。
Connected to the database
Disconnected from database
何が問題なのですか?