java 关于mysql

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

Mysql 服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection。

在C3P0 pools中的connections如果空闲超过8小时,mysql将其断开,而C3P0并不知道该connection已经失效,如果这时有 Client请求connection,C3P0将该失效的Connection提供给Client。

使用hibernate: 
<property name="connection.autoReconnect">true</property>  <!--这个是最主要的--> 
<property name="connection.autoReconnectForPools">true</property> 
<property name="connection.is-connection-validation-required">true</property> 
加入以上property,可解决此问题,如果未使用hibernate等持久化管理框架,可在mysql的url中加入autoReconnect=true,这样就可以解决。
 
 
port=3306下面添加
# this is myown dinifition for mysql connection timeout
wait_timeout=31536000
interactive_timeout=31536000
 
mysql>show variables like '%timeout%';  
可以进行查看
欢迎指正:haizi2014@qq.com
原文地址:https://www.cnblogs.com/hcfan/p/4680057.html