com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure
我的连接到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.
发生了什么事?
用于获取连接的代码:
private static Connection getDBConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
String username = "user";
String password = "pass";
String url = "jdbc:mysql://www.domain.com:3306/dbName?connectTimeout=3000";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}