com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from
来源:互联网 发布:网络配置方案 编辑:程序博客网 时间:2024/05/01 22:46
出现问题:
新的应用发布后发现每过一段时间后tomcat就会报错。错误信息大概如下:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 152,219,305 milliseconds ago. The last packet sent successfully to the server was 152,219,305 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)
在百度里搜到很多,但是都没有解决我的问题,今天看到了一篇写的还算靠谱的文章,http://blog.csdn.net/liuqiyu/article/details/6092377他说的确实没错,但是最关键的地方他说的有点模糊,就是在什么地方修改配置文件,害的我琢磨了好久,我看他也是看别人的方法,而且我估计理解稍微有点错误,修改的位置应该是
[client]
port=3306
[mysql]
default-character-set=gbk
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
wait_timeout=1814400
# The TCP/IP Port the MySQL Server will listen on
port=3306
上面是我贴出来的数据库my.ini配置文件的部分,把wait_timeout=1814400 写在这个位置就没有问题了!!
解释及解决办法:
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 得刷新应用才行.
不用hibernate的话, connection url加参数: autoReconnect=true
用hibernate的话, 加如下属性:
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
要是还用c3p0连接池:
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packe
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
- Mysql异常com.mysql.jdbc.exceptions.jdbc4.CommunicationsException..CommunicationsException: Communicati
- (2)Mysql ----- The last packet successfully received from the server was *** millisecond ago.The
- mysql The last packet successfully received from the server was XXX seconds ago
- MySQL: Communications link failure,The last packet successfully received from the server
- MYSQL Communications link failure,The last packet successfully received from the server was
- mysql重连,连接丢失:The last packet successfully received from the server
- mysql重连,连接丢失:The last packet successfully received from the server
- mysql重连,连接丢失:The last packet successfully received from the server
- mysql重连,连接丢失:The last packet successfully received from the server
- mysql重连,连接丢失:The last packet successfully received from the server--转载
- mysql重连,连接丢失:The last packet successfully received from the server--转载
- MySQL之——重连,连接丢失:The last packet successfully received from the serve
- mysql重连,连接丢失:The last packet successfully received from the server--转载
- mysql重连,连接丢失:The last packet successfully received from the server
- log4j配置
- 3.12 MonoForAndroid用户人机界面--具有交互功能的对话框
- [Xamarin]测试账号申请与到期后如何续用
- 谈谈asp,php,jsp的优缺点
- Linux常用命令大全
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from
- php-fpm(PHP-FPM是一个PHPFastCGI管理器)
- 图像基本处理算法的简单实现(一)
- 如何高效地判断数组中是否包含某特定值
- ibatis 开发中的经验 (二)ibatis 命名空间配置以及左中右连接查询
- visual studio 2010 快捷键大全
- 看懂Gradle脚本(2)- Groovy语言的闭包语法
- Gameloft游戏开发面试题
- Yii的重写规则与URL的管理