com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭

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设置为局部变量,即可解决这个问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值