Home >Database >Mysql Tutorial >How to Troubleshoot \'com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed\'?
"com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed"
Issue:
When deploying an application to a remote server, a MySQL connection exception occurs after the application runs for over a day. The exception message states that no operations are allowed after the connection is closed.
Cause:
The exception is likely caused by a broken connection due to inactivity. The default timeout settings for the MySQL server and client might be too short, leading to connections being closed prematurely.
Solution:
1. Adjust Server and Client Timeouts
Server (MySQL Configuration):
Client (Hibernate/JDBC Connection Pool):
2. Enable Connection Pooling
Additional Measures:
Updated Hibernate Configuration:
The provided updated Hibernate configuration file uses C3P0 connection pooling and includes the recommended settings:
<hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xyz</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <!-- Enable C3P0 connection pooling --> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="c3p0.max_size">20</property> <property name="c3p0.min_size">5</property> <property name="c3p0.max_statements">0</property> <property name="c3p0.timeout">600</property> <property name="c3p0.idleConnectionTestPeriod">3600</property> <property name="c3p0.testConnectionOnCheckout">true</property> </session-factory> </hibernate-configuration>
The above is the detailed content of How to Troubleshoot \'com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed\'?. For more information, please follow other related articles on the PHP Chinese website!