码迷,mamicode.com
首页 > 数据库 > 详细

开发中出现的异常com.mysql.jdbc.CommunicationsException

时间:2017-01-10 22:45:49      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:com.mysql.jdbc.communicationsexception

web开发遇到的异常:

com.mysql.jdbc.CommunicationsException:The last packet successfully received from the server was58129 seconds ago.Thelast packet sent successfully to the server was 58129 seconds ago, which islonger than the server configured value of ‘wait_timeout‘. You should considereither expiring and/or testing connection validity before use in yourapplication, increasing the server configured values for client timeouts, orusing the Connector/J connection property ‘autoReconnect=true‘ to avoid thisproblem.


解决办法:

如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat.

不用hibernate的话, connection url加参数: autoReconnect=true


hibernate的话, 加如下属性: 

<propertyname="connection.autoReconnect">true</property>

<propertyname="connection.autoReconnectForPools">true</property>

<propertyname="connection.is-connection-validation-required">true</property>

 

要是还用c3p0连接池:

<propertyname="hibernate.c3p0.acquire_increment">1</property>

<propertyname="hibernate.c3p0.idle_test_period">0</property>

<propertyname="hibernate.c3p0.timeout">0</property>

<propertyname="hibernate.c3p0.validate">true</property>

 


或者最王道的解决办法,那就是直接修改mysql的配置文件my.ini 在配置文件的最后增加wait_timeout=343232后面的数字是以秒计算。改个10100年多方便的。


开发中出现的异常com.mysql.jdbc.CommunicationsException

标签:com.mysql.jdbc.communicationsexception

原文地址:http://10229180.blog.51cto.com/10219180/1890766

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!