我的代码导致此错误,谁可以帮助我?
我的程序是在 Android 中。
错误
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.
功能:
public Connection getConexato() throws ClassNotFoundException, SQLException, java.sql.SQLException, InstantiationException, IllegalAccessException {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = (Connection) DriverManager.getConnection("jdbc:mysql://179.219.251.158:3306/partcatalog","root","teste123");
return conn;
}
Ping 到机器服务器:
C:\Users\psysvica>ping 179.219.251.158
Disparando 179.219.251.158 com 32 bytes de dados:
Resposta de 179.219.251.158: bytes=32 tempo=53ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=39ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=82ms TTL=56
Resposta de 179.219.251.158: bytes=32 tempo=43ms TTL=56
最佳答案
考虑以下因素:
- 数据库服务器启动或关闭
- 服务器的IP地址
- 端口号正确或错误
因此您可以通过 ping 数据库服务器来验证这一点。如果需要,您可能需要重新启动数据库服务器。
关于java - 无法连接到 MySQL 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19657469/