我有这个错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 54,607,614 milliseconds ago.
The last packet sent successfully to the server was 54,607,614 milliseconds ago. is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
但是我不知道我的程序中有什么错误,我有autoReconnect=true
...:
connection = DriverManager.getConnection(
"jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true&useSSL=false", username, password
);
发布于 2021-01-04 19:49:08
这是一条警告消息,说明在指定时间内没有sql命令发送到Mysql服务器。JDBC可以在这样的事件上执行自动重新连接。
添加另一个参数
cmaxReconnets=5
在放弃之前尝试重新连接5次。还有一个用于重试前的初始超时的参数
initialTimeout=1
您可以在获取连接时将其添加到属性中。
DriverManager.getConnection(connectionString, properties)
https://stackoverflow.com/questions/65562034
复制相似问题