DBCP错误:java.sql.SQLException: Already closed.

遇到这个错误,搜索了一下解决方法,经测试好用。
java.sql.SQLException: Already closed.
        at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
        at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
        at com.lwjlaser.citation2DB.Citation.controller(Citation.java:84)
        at com.lwjlaser.citation2DB.DealCitation.doPost(DealCitation.java:46)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)


原因:You're probably running into the fact that MYSQL closes connections  
which have been open "too long".
Probably if you make the request to the server again, you'll find that  
it works because the connection is reopened.
解决方法: One way to deal with this is to add the following to your context.xml  
Resource:

validationQuery="select 1"


代价:This causes a very cheap test query to always be run first; if the  
connection has been closed, this gets the failure, and
then a new connection is opened

你可能感兴趣的:(java,apache,sql,tomcat,SQL Server)