2
回答
奇怪连接mysql数据库过1晚上后,报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
终于搞明白,存储TCO原来是这样算的>>>   

问题如下:

 1.系统使用hibernate连接数据库,分别连接两个数据库 配置如下:

    (1):

    <property name="connection.url">jdbc:mysql://10.200.89.38:3306/ad_sso</property>

   (2)

    <property name="connection.url">jdbc:mysql://10.200.89.38:3306/monitor_center</property>

 2.  启动服务器后,不管后台代码查询那个数据库里的数据,一切都正常。不过过了几个小时(8小时或者一晚上),那么后台访问(1)数据库总是报如下异常:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 65,962,396 milliseconds ago. The last packet sent successfully to the server was 65,962,396 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.

3.在网上找了 说是,Mysql服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该 connection。而hibernate获取连接的时候认为连接池里的这个连接还是有效的,所以就拿来使用,这时候就报错了。

 按照网上的说的解决方法,配置了连接参数:

           <property name="connection.autoReconnect">true</property> 
        <property name="connection.autoReconnectForPools">true</property> 
        <property name="connection.is-connection-validation-required">true</property>
 

 但,还是不管用啊!

请教,给各位oscer的朋友,有遇到这个问题的吗?


举报
小布丁女
发帖于5年前 2回/4K+阅
顶部