我尝试通过 mysql-connector-java-5.1.21-bin.jar 库连接到 MySQL。这是我的代码:
class Test {
private static final String CONNECTION = "jdbc:mysql://x.x.x.x:3306/db";
private void getMySQL() {
Connection con = null;
String str_res = "";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
// Properties for user and password.
Properties p = new Properties();
p.put("user","***");
p.put("password","***");
// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION, p);
...
} catch (Exception e) {}
}
但我有一个网络异常:
com.mysql.jdbc.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.
java.net.SocketException: The operation timed out
null
null
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.
0
0
怎么了?