首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java MySQL ?autoReconnect=true

Java MySQL ?autoReconnect=true
EN

Stack Overflow用户
提问于 2021-01-04 19:36:16
回答 1查看 312关注 0票数 0

我有这个错误:

代码语言:javascript
运行
复制
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...:

代码语言:javascript
运行
复制
connection = DriverManager.getConnection(
"jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true&useSSL=false", username, password
);
EN

回答 1

Stack Overflow用户

发布于 2021-01-04 19:49:08

这是一条警告消息,说明在指定时间内没有sql命令发送到Mysql服务器。JDBC可以在这样的事件上执行自动重新连接。

添加另一个参数

代码语言:javascript
运行
复制
cmaxReconnets=5

在放弃之前尝试重新连接5次。还有一个用于重试前的初始超时的参数

代码语言:javascript
运行
复制
initialTimeout=1

您可以在获取连接时将其添加到属性中。

代码语言:javascript
运行
复制
DriverManager.getConnection(connectionString, properties)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65562034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档