开发者社区> 问答> 正文

奇怪连接mysql数据库过1晚上后,报com.mysql.jdbc.except?报错

问题如下:

 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的朋友,有遇到这个问题的吗?


展开
收起
爱吃鱼的程序员 2020-06-22 21:33:18 470 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    同求答案啊。。是了好多方法都是只讲了一点点。设呢吗采用c3po,具体要倒那些包,怎么配各有不同。。每一个成功的。。 

    修改MYSQL连接时间,设置大一点。

    2020-06-22 21:33:34
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像