com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet success

下一行code 2012-11-30 10:37:16
新发布的应用,昨天一天正常运行,没有问题,但是今天早上刚刚一测试就报错:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 60,547,352 milliseconds ago. The last packet sent successfully to the server was 60,547,352 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

日志文件从这个地方开始往下只要是数据库操作就开始报错:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

还有这个错:
No operations allowed after connection closed.

再往下就是:
java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:803)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6985)
at com.dz.servlet.LoginServlet.service(LoginServlet.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:845)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:688)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1315)
at java.lang.Thread.run(Unknown Source)


数据库版本:mysql 5.1.50
服务器版本:tomcat5.5
上面所有的错误重启tomcat后就没有了,但是,总不能让我每天都跑来重启服务器吧,所以这个问题还得解决,要想解决这个问题就得靠坛子里的大佬们了!!各位高手!请指点一下!!
...全文
10355 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
下一行code 2012-12-05
  • 打赏
  • 举报
回复
谢谢各位的回复 我的解决方法是在mysql数据库的配置文件my.ini中添加了两行配置,位置在[mysqld]下面 具体如下 [mysqld] wait_timeout=1814400 interactive_timeout=1814400 修改后再没有出现问题,但是理论上在修改完21天后会出现这个问题,因为1814400=21天!
下一行code 2012-12-05
  • 打赏
  • 举报
回复
引用 4 楼 torytin 的回复:
那是你的连接空闲超时了(比如一个晚上没有人访问,就超过数据库的空闲断开时间),而你还继续用那个连接,当然会出错了。具体可以看下这篇博文 http://javacrazyer.iteye.com/blog/721393/
谢谢回答,请看我在6楼的回复,我是通过这种方法解决问题 的
下一行code 2012-12-05
  • 打赏
  • 举报
回复
引用 3 楼 mutoujuelian 的回复:
我帮你在google上找了一个解决的,你看看是不是由于 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 今天做学校的精品课程网 ,又遇到了一些问题,错误提示是:Operation not allowed after ResultSet closed,在网上找了一下,一篇文章解决了我的问题,如下 一个stmt多个rs进行操作引起的Re……
感谢你的回答,我在网上找到的方法在Mysql数据库中的my.ini中的[mysqld]下面加了两行配置解决问题了 添加配置如下 [mysqld] wait_timeout=1814400 interactive_timeout=1814400 修改这个后没有再出现问题!!
sdds123sdds 2012-12-04
  • 打赏
  • 举报
回复
引用 4 楼 torytin 的回复:
那是你的连接空闲超时了(比如一个晚上没有人访问,就超过数据库的空闲断开时间),而你还继续用那个连接,当然会出错了。具体可以看下这篇博文 http://javacrazyer.iteye.com/blog/721393/
你可以看看,对解决问题有帮助
torytin 2012-12-04
  • 打赏
  • 举报
回复
那是你的连接空闲超时了(比如一个晚上没有人访问,就超过数据库的空闲断开时间),而你还继续用那个连接,当然会出错了。具体可以看下这篇博文 http://javacrazyer.iteye.com/blog/721393/
mutoujuelian 2012-12-03
  • 打赏
  • 举报
回复
我帮你在google上找了一个解决的,你看看是不是由于 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 今天做学校的精品课程网 ,又遇到了一些问题,错误提示是:Operation not allowed after ResultSet closed,在网上找了一下,一篇文章解决了我的问题,如下 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 一个stmt多个rs进行操作. 那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作. 不能互相交替使用,会引起rs已经关闭错误. 错误的代码如下: stmt=conn.createStatement(); rs=stmt.executeQuery("select * from t1"); rst=stmt.executeQuery("select * from t2"); rs.last();//由于执行了rst=stmt.executeQuery(sql_a);rs就会被关闭掉!所以程序执行到此会提示ResultSet已经关闭.错误信息为:java.sql.SQLException: Operation not allowed after ResultSet closed rst.last(); 正确的代码: stmt=conn.createStatement(); rs=stmt.executeQuery("select * from t1"); rs.last();//对rs的操作应马上操作,操作完后再从数据库得到rst,再对rst操作 rst=stmt.executeQuery("select * from t2"); rst.last(); 原因是: The object used for executing a static SQL statement and returning the results it produces. By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists. 一个stmt最好对应一个rs, 如果用一个时间内用一个stmt打开两个rs同时操作,会出现这种情况. 所以解决此类问题:1.就多创建几个stmt,一个stmt对应一个rs;2.若用一个stmt对应多个rs的话,那只能得到一个rs后就操作,处理完第一个rs后再处理其他的,如上"正确代码". 多个stmt对应各自的rs. stmt=conn.createStatement(); stmt2=conn.createStatement(); rs=stmt.executeQuery("select * from t1"); rst=stmt2.executeQuery("select * from t2"); rs.last(); rst.last();
下一行code 2012-12-03
  • 打赏
  • 举报
回复
自己顶!!周末休息两天,今天早上来第一件事情就是看服务器,果然有报错,而且应用访问不了,重启了一下tomcat就又好了,报错信息和上面的一模一样!!高手请指点!!
下一行code 2012-12-03
  • 打赏
  • 举报
回复
我继续顶!!自己顶起来

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧