我有一个与 MySQL DB 交互的 Java Web 应用程序。我从不关闭数据库连接,并且使用单例来处理连接实例。
问题是,当我保持连接打开时间太长并尝试在应用程序上执行某些操作后,我收到此错误:
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
吗?或者为什么会发生这种情况?我虽然默认情况下它会自动重新连接。或者我应该在每次请求后继续关闭数据库?这会降低性能,这对于这个应用程序来说至关重要。
我可以提供更多信息吗?
最佳答案
虽然您不应该让连接打开那么长时间..但要回答您有关自动重新连接的问题。它是一个可以在连接 URL 中设置的属性,例如
url="jdbc:mysql://localhost:3306/confluence?autoReconnect=true"
关于java - MySQL 连接消失 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39694866/