[HOW TO] fix :com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed

The last week, when check the logs of Tomcat, I see:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed

Humn, it looks like the MySQL connection has a problem about connection pooling. Mysql implicitly closed the db connection because the db connection has been inactive too long time ( 34,247,052 milliseconds ).so you prgram fetch a bad connection from connection-pool, and that cause the 'MySQLNonTransientConnectionException: No operations allowed after connection closed'

mysql suggests '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.'

How to solve it?

In case of me, If you use Mysql, you can set autoReconnect property:

url="jdbc:mysql://localhost:3307/merchant-mc useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"


Thank you for reading this article, please a comment if you are interested.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

0 nhận xét:

Post a Comment