

Using the Connector/J connection property 'autoReconnect=true'I tried this solution by appending the property autoReconnect=true to the database URL but it doesn’t work. However, the problem can occur again if the connection has been idle longer than the timeout value. Increasing the server configured values for client timeouts:This is possible by updating the setting file ( my.ini) on MySQL server machine - changing the wait_timeoutvalue with longer value. Furthermore, opening a database connection is an expensive operation so it’s not optimal to open and close database connection for every user’s request - that’s why database connection pooling comes into play. Or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.Let’s consider each suggestion mentioned above.Įxpiring and/or testing connection validity before use in your application:This requires changing or re-structuring the existing code, which is difficult to implement. Increasing the server configured values for client timeouts, You should consider either expiring and/or testing connection validity before use in your application, Is longer than the server configured value of 'wait_timeout'. Solutions to fix JDBCConnectionExceptionIf you look closely at the exception stack trace, you will see some suggestions to fix the problem: The last packet sent successfully to the server was 390,061 milliseconds ago. So if a connection has been idle longer than this timeout value, it will be dropped by the server.Therefore, when the Java database application has been idle longer than MySQL server’s connection timeout value, and the end user tries to connect again, Hibernate reuses the idle connection which was already dropped by the server, hence JDBCConnectionExceptionis thrown. And MySQL database server has a timeout value for each connection (default is 8 hours or 28,800 seconds).


That means it keeps a database connection open to be reused later. So why is JDBCConnectionException thrown?By default, Hibernate uses its internal database connection pool library. So this problem should be solved completely. Though this is not a serious problem in development, but it’s not good under the end-user’s perspective and they will see the application is buggy and their work is interrupted. And the problem keeps happening again if the user left the application for a quite long time and come back. …If you refresh or try to connect again, the application successfully connected to the database.
Beatunes unable to acquire jdbc connection software#
: :Ĭaused by: :Ĭaused by: .jdbc4.CommunicationsException: Communications link failureĬaused by: : Software caused connection abort: recv failed The last packet sent successfully to the server was 35 milliseconds ago. The exception stack trace would look like this: The last packet successfully received from the server was 297,215,018 milliseconds ago. When developing Java database web applications with Hibernate/JPA and MySQL, you will face a connection error if the user has not used the application for a long time.
