java.sql.SQLException:连接关闭后不允许任何操作
我已经构建了一个使用session维护的应用程序。 它使用JDBC和mysql。
在服务器(Apache Tomcat 6)上部署应用程序时。 我可以登录并注销会话。 工作完全没问题。
现在我让服务器继续运行24小时。 现在第二天我输入凭据后尝试登录系统,单击“登录”按钮后,我在网页上收到错误,如下所示:(原因是什么?)
Http状态500
例外
org.apache.jasper.JasperException:在第11行处理JSP页面/login.jsp时发生exception
9: Connection con =ConnectionProvider.getConnection(); 10: System.out.println("con "+con); 11: con.setAutoCommit(false); 12: Statement st = con.createStatement(); 13: ResultSet rs; 14: rs = st.executeQuery("select * from ejduge_login where uname='" + userid + "' and pass='" + pwd +"'"); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause javax.servlet.ServletException: java.sql.SQLException: No operations allowed after connection closed. org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.login_jsp._jspService(login_jsp.java:97) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause java.sql.SQLException: No operations allowed after connection closed. com.mysql.jdbc.Connection.checkClosed(Connection.java:2726) com.mysql.jdbc.Connection.setAutoCommit(Connection.java:498) org.apache.jsp.login_jsp._jspService(login_jsp.java:65) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
提前致谢!
我发现,关闭连接的默认时间(如果它已经非活动太长时间)是MYSQL的28800秒(8小时) (而不是34,247,052毫秒) 。
show global variables;
在MYSQL中,我将该值重置为172800秒(根据我的要求,48小时)
set global wait_timeout=172800;
它工作得很好。
非常感谢您的帮助!
如果连接长时间处于非活动状态( 默认为34,247,052毫秒 ),mysql将隐式关闭连接。
这会导致No operations allowed after connection closed
错误No operations allowed after connection closed
。 所以你可以增加非活动状态超时或通过有效的连接池处理它
它现在可能工作正常,它会在172800秒后出错,你应该添加检查状态值并设置小于172800的值。
就像c3p0 idleConnectionTestPeriod和maxIdleTime一样。