Java.sql.SQLException: Closed Connection resolution

Source: Internet
Author: User
Tags aop

If the program does not perform database operations for a long time, the Connection in the data source is likely to have been disconnected. This can be caused by a firewall, or the time-out of the database setting for the connection. This is used by C3P0 to connect to the Oracle database, which causes the exception information to be:

Org.springframework.transaction.TransactionSystemException:Could not roll back Hibernate transaction; Nested exception is Org.hibernate.TransactionException:rollback failed

At Org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback (Hibernatetransactionmanager.java : 503)

At Org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback ( abstractplatformtransactionmanager.java:845)

At Org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback ( abstractplatformtransactionmanager.java:822)

At Org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing ( transactionaspectsupport.java:411)

At Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (transactioninterceptor.java:114)

At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:172)

At Org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (exposeinvocationinterceptor.java:90)

At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:172)

At Org.springframework.aop.framework.cglib2aopproxy$dynamicadvisedinterceptor.intercept (Cglib2AopProxy.java:622 )

At com.platform.dao.tasksdao$ $EnhancerByCGLIB $ $abcb 28f5.gettaskbyid (<generated>)

At Com.platform.manager.TasksManager.getTaskById (tasksmanager.java:287)

At Com.platform.manager.TasksManager.checkResult (tasksmanager.java:300)

At Com.platform.timer.TimerBase.tasksListener (timerbase.java:149)

At Com.platform.timer.TimerBase.run (timerbase.java:81)

At Java.util.TimerThread.mainLoop (timer.java:555)

At Java.util.TimerThread.run (timer.java:505)

Caused By:org.hibernate.TransactionException:rollback failed

At Org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback (abstracttransactionimpl.java:215)

At Org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback (Hibernatetransactionmanager.java : 500)

... More

caused By:org.hibernate.TransactionException:unable to rollback against JDBC connection

At Org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback (jdbctransaction.java:167)

At Org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback (abstracttransactionimpl.java:209)

... More

Caused by:java.sql.SQLException: Closed connection

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:111)

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:145)

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:207)

At Oracle.jdbc.driver.PhysicalConnection.rollback (physicalconnection.java:1160)

At Com.alibaba.china.jdbc.proxy.simple.ConnectionProxy.rollback (connectionproxy.java:228)

At Com.mchange.v2.c3p0.impl.NewProxyConnection.rollback (newproxyconnection.java:855)

At Org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback (jdbctransaction.java:163)

... More

The exception is thrown where the transaction management of Spring is TransactionManager, not program code. Even if you catch an exception, using sessionfactory.opensession throws the following exception:

Org.springframework.transaction.TransactionSystemException:Could not roll back Hibernate transaction; Nested exception is Org.hibernate.TransactionException:rollback failed

At Org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback (Hibernatetransactionmanager.java : 503)

At Org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback ( abstractplatformtransactionmanager.java:845)

At Org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback ( abstractplatformtransactionmanager.java:822)

At Org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing ( transactionaspectsupport.java:411)

At Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (transactioninterceptor.java:114)

At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:172)

At Org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (exposeinvocationinterceptor.java:90)

At Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (reflectivemethodinvocation.java:172)

At Org.springframework.aop.framework.cglib2aopproxy$dynamicadvisedinterceptor.intercept (Cglib2AopProxy.java:622 )

At com.platform.dao.tasksdao$ $EnhancerByCGLIB $ $abcb 28f5.gettaskbynewsession (<generated>)

At Com.platform.manager.TasksManager.checkResult (tasksmanager.java:303)

At Com.platform.timer.TimerBase.tasksListener (timerbase.java:149)

At Com.platform.timer.TimerBase.run (timerbase.java:81)

At Java.util.TimerThread.mainLoop (timer.java:555)

At Java.util.TimerThread.run (timer.java:505)

Caused By:org.hibernate.TransactionException:rollback failed

At Org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback (abstracttransactionimpl.java:215)

At Org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback (Hibernatetransactionmanager.java : 500)

... More

caused By:org.hibernate.TransactionException:unable to rollback against JDBC connection

At Org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback (jdbctransaction.java:167)

At Org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback (abstracttransactionimpl.java:209)

... More

Caused By:java.sql.SQLException:Io exception: Software caused connection Abort:recv failed

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:111)

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:145)

At Oracle.jdbc.driver.DatabaseError.throwSqlException (databaseerror.java:254)

At Oracle.jdbc.driver.T4CConnection.doRollback (t4cconnection.java:577)

At Oracle.jdbc.driver.PhysicalConnection.rollback (physicalconnection.java:1163)

At Com.alibaba.china.jdbc.proxy.simple.ConnectionProxy.rollback (connectionproxy.java:228)

At Com.mchange.v2.c3p0.impl.NewProxyConnection.rollback (newproxyconnection.java:855)

At Org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback (jdbctransaction.java:163)

... More

The solution is to:

C3P0 Custom Configuration:

<!--database Connection declaration--

<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource"

destroy-method= "Close" >

<property name= "Driverclass" value= "Com.alibaba.china.jdbc.SimpleDriver"/>

<!--<property name= "Driverclass" value= "Oracle.jdbc.OracleDriver"/>--

<property name= "Jdbcurl" value= "Jdbc:oracle:thin:@202.116.70.180:61166:orcl"/>

<!--check for idle connections in all connection pools every 60 seconds. Default:0--

<property name= "idleconnectiontestperiod" value= "/>"

<!--If set to true then officer the validity of the connection while the connection is made. Default:false--

<property name= "Testconnectiononcheckin" value= "true"/>

<!--C3P0 will build a blank table named Test and test it with its own query statement. If this parameter is defined, then the attribute preferredtestquery will be ignored. You cannot do anything on this test sheet, it will be for C3P0 testing only

Use. Default:null--

<property name= "automatictesttable" value= "Test"/>

<property name= "Properties" >

<props>

<prop key= "Clientencoding" >GBK</prop>

<prop key= "Serverencoding" >CP1252</prop>

<prop key= "User" >WDS</prop>

<prop key= "Password" >HelloOracle</prop>

</props>

</property>

</bean>

A configuration item must be a child of <bean> and not a child of <properties>, otherwise it will not work.

Reference:

http://my.oschina.net/tianzimensheng/blog/65225

Http://www.cnblogs.com/younes/archive/2012/06/01/2529483.html

Http://www.cnblogs.com/safeking/archive/2007/02/01/637067.html

Java.sql.SQLException: Closed Connection resolution

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.