MySQLNonTransientConnectionException:无法创建与数据库服务器的连接。已尝试重新连接 3 次。放弃
2022-09-03 16:02:04
我在连接到数据库时遇到问题。我认为有一个我不知道的地方有一个设置,需要改变。我在这里有一些非常基本的代码:
public static void main(String[] args)
{
try
{
Connection con = DriverManager.getConnection("jdbc:mysql://IP:3306/TABLENAME?autoReconnect=true","USERNAME", "PASSWORD");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
显然与登录信息。它会导致此错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: 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.
Caused by: java.net.ConnectException: Connection refused
我已经查看了大约10个关于同一问题的不同帖子,并尝试了他们的解决方案,但仍然无法使其正常工作。