本文介绍了java.sql.SQLException:连接关闭后不允许任何操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个使用session维护的应用程序。
它使用JDBC& mysql。

I have build an application, maintained with session.It uses JDBC & mysql.

当应用程序部署在服务器上时(Apache Tomcat 6)。我可以登录并注销会话。工作完全正常。

When the application is deployed on server (Apache Tomcat 6). I can log in and log out of the session. Works totally fine.

现在我让服务器继续运行24小时。现在第二天我输入凭据后尝试登录系统,点击登录按钮我在网页上收到错误如下:
(这是什么原因?)

Now I keep the server running for next 24 hrs. And now on the next day I try to log in into the system after entering the credentials, on clicking the Login button I get the error on web page as below:(what is the cause for this?)

Http status 500

异常

org.apache.jasper.JasperException:在第11行处理JSP页面/login.jsp时发生异常

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 (&不是34,247,052毫秒),则关闭连接的默认时间(如果它已处于非活动状态的时间太长)为28800秒(8小时)。

Well I found, the default time for closing connection if it has been inactive too long is 28800 seconds(8 hrs) for MYSQL (& not 34,247,052 milliseconds).

show global variables;

在MYSQL中,我将该值重置为172800秒(根据我的要求,48小时)

In MYSQL, I reset that value to 172800 seconds(48 hrs as per my requirement) using

set global wait_timeout=172800;

它工作正常。

谢谢很多帮助!

这篇关于java.sql.SQLException:连接关闭后不允许任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:45