[2019-01-07 09:44:02] ERROR
:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
link failure
[2019-01-07 09:44:02]
[2019-01-07 09:44:02] The last packet sent successfully to the server was 0
milliseconds ago. The driver has not received any packets from the server.
提交库..
mysql-connector-java-5.1.47-bin.jar
mysql-connector-java-5.1.47.jar
JDBC URL更改
jdbc:mysql://IP:3306/ID -> jdbc:mysql://IP:3306/ID?autoReconnect=true
更改的错误消息。
[2019-01-07 11:04:32] Error :
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could
not create connection to database server. Attempted reconnect 3 times.
Giving up.
private final static String DRIVER = "com.mysql.jdbc.Driver";
private final static String URL =
"jdbc:mysql://IP:3306/ID?autoReconnect=true;
public static void CsNumberCheck(String s) {
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(URL, "ID", "PW");
System.out.println(conn);
stat = conn.createStatement();
int result = 0;
sql = Query;
rs = stat.executeQuery(sql);
while ( rs.next() ) {
result = rs.getInt(1);
}
rs.close();
stat.close();
System.out.println(result);
CsNumberResult(result, OrangeEmail);
}
catch (ClassNotFoundException e) {
System.out.println("Driver Loading Failed..");
}
catch (SQLException e) {
System.out.println("Error : " + e);
}
}
ControlDAO.CsNumberCheck(s);
答案 0 :(得分:0)
检查Windows服务以查看MySQL服务器是否正在运行。那可能是原因。如果不是,请启动它并尝试重新连接。