com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭的解决方案
ERROR http-8080-13 org.dbforms.event.datalist.dao.AbstractDataSource - getCurrent
com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.createStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.createStatement(Unknown Source)
at org.dbforms.conprovider.SingleConnectionWrapper.createStatement(SingleConnectionWrapper.java:379)
at org.dbforms.event.datalist.dao.DataSourceJDBC.open(DataSourceJDBC.java:487)
at org.dbforms.event.datalist.dao.AbstractDataSource.getCurrent(AbstractDataSource.java:104)
at org.dbforms.event.datalist.dao.DataSourceFactory.getCurrent(DataSourceFactory.java:95)
at org.dbforms.event.datalist.GotoEvent.processEvent(GotoEvent.java:267)
at org.dbforms.taglib.DbFormTag.doStartTag(DbFormTag.java:1757)
at org.apache.jsp.yy.car_005forder_005fmodify_jsp._jspService(car_005forder_005fmodify_jsp.java:876)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.dbforms.servlets.Controller.process(Controller.java:285)
at org.dbforms.servlets.base.AbstractServletBase.process_internal(AbstractServletBase.java:123)
at org.dbforms.servlets.base.AbstractServletBase.doPost(AbstractServletBase.java:86)
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.dbforms.util.external.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:190)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
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:857)
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)
Connection对象不能作为全局的参数。
这个问题是并发的问题.. 两个线程同时访问Connection对象,其中一个线程把connection关了,另外一个线程拿着已关闭的连接去用的时候就会报这个错误了
public static Connection GetConnection() {
Connection conn = null; //请注意这里设置为局部变量
try {
conn = DriverManager.getConnection(url, username, password);
} catch (Exception e) {e.printStackTrace();}
return conn;
}
将Connection conn设置为局部变量,即可解决这个问题。