MySQL连接在Java中消失了

MySQL连接在Java中消失了,java,mysql,Java,Mysql,我有一个与MySQL DB交互的Java web应用程序。我从不关闭DB连接,我使用singleton来处理连接实例 问题是,在我将连接打开太长时间并尝试在应用程序上执行某些操作后,我遇到以下错误: The last packet successfully received from the server was 211,710,369 milliseconds ago. The last packet sent successfully to the server was 211,710,3

我有一个与MySQL DB交互的Java web应用程序。我从不关闭DB连接,我使用singleton来处理连接实例

问题是,在我将连接打开太长时间并尝试在应用程序上执行某些操作后,我遇到以下错误:

The last packet successfully received from the server was 211,710,369 milliseconds ago.  The last packet sent successfully to the server was 211,710,398 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
?或者为什么会这样?我认为默认情况下它会自动重新连接。还是每次请求后我都应该关闭数据库?这会降低性能,这对该应用程序至关重要


我能提供更多信息吗?

使用以下方法保持连接的活动状态

首先将其用于mysql连接

jdbc:mysql://localhost/<database>?autoReconnect=true

尽管您不应该让连接打开那么长时间。。但是要回答你关于自动恢复连接的问题。它是一个可以在连接url中设置的属性,例如

url="jdbc:mysql://localhost:3306/confluence?autoReconnect=true"

您真的让连接闲置2.45天吗?如果连接闲置2½天,则打开和关闭连接不会成为性能问题。经典。性能问题。
url="jdbc:mysql://localhost:3306/confluence?autoReconnect=true"