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

Source: Internet
Author: User

Error-no operations allowed after connection closed. org.hibernate.exception.jdbcconnectionexception:could not Execute Queryat Org.hibernate.exception.SQLStateConverter.convert (sqlstateconverter.java:74) at Org.hibernate.exception.JDBCExceptionHelper.convert (jdbcexceptionhelper.java:43) at Org.hibernate.loader.Loader.doList (loader.java:2148) at Org.hibernate.loader.Loader.listIgnoreQueryCache ( loader.java:2029) at Org.hibernate.loader.Loader.list (loader.java:2024) at Org.hibernate.loader.hql.QueryLoader.list (queryloader.java:375) at Org.hibernate.hql.ast.QueryTranslatorImpl.list (querytranslatorimpl.java:308) at Org.hibernate.engine.query.HQLQueryPlan.performList (hqlqueryplan.java:153) at Org.hibernate.impl.SessionImpl.list (sessionimpl.java:1106) at Org.hibernate.impl.QueryImpl.list (Queryimpl.java : 79) Analysis, the reason for this exception is: MySQL server default "Wait_timeout" is 8 hours, that is, a connection idle for more than 8 hours, MySQL will automatically disconnect the connection. This is the problem, in the C3P0 pools connections if idle for more than 8 hours, MySQL will disconnect it, and c3p0 do not know that the connection has failed, if there is a client request ConnecTion,c3p0 the failure of the connection to the client, will cause the above exception. A) There are 3 ways to solve the:    increase wait_timeout time.     Reduce the lifetime of connection in connection pools.     Test the effectiveness of connection in connection pools. b) Specific solutions:
1, change the JDBC driver, Jdbc3.1.0-alpha and previous versions of this issue, download the new JDBC Driver 2, use Hibernate configuration: Hibernate: <property name= " Connection.autoreconnect ">true</property> <!--This is the most important--<property name=" Connection.autoreconnectforpools ">true</property> <property name=" Connection.is-connection-validation-required ">true</property> Add the above property to resolve this issue, If you do not use a persistence management framework such as Hibernate, you can add autoreconnect=true to the MySQL URL to resolve it. The reason is simple. Shutting down connections after the end of a database operation is the right thing to do, no big deal. As for the appearance:No operations allowed after connection closed。 The reason for this problem is only one, you here and the database connection connection is a static, program sharing this one connection. So the first time on the database operation is not a problem, when the connection closed, the second time also want to operate the database connection certainly does not exist.

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.