C3P0连MYSQL失效问题

 由于Mysql服务器默认的wait_timeout是8小时,也就是说一个connection空闲超过8个小时,     Mysql将自动断开该 connection。然而在C3P0 pools中的connections如果空闲超过8小时,     Mysql将其断开,而C3P0并不知道该connection已经失效,如果这时有 Client请求connection,     C3P0将该失效的Connection提供给Client,将会造成异常。     解决方法可为:1.jdbcUrl上面加一个autoReconnect=true       2.由于autoReconnect=true 在新的connector/J版本里面已经deprecated了,文档里面建议不要使用。        所以配置参数idleConnectionTestPeriod,automaticTestTable

 

而配置 automaticTestTable却 会报CLOSE BY CLIENT STACK TRACE,故选择配置preferredTestQuery 而不是 automaticTestTable 。

引用自:http://blog.csdn.net/hallelujah_chen/article/details/6016132

猜你喜欢

转载自blog.csdn.net/sunnyfirefox/article/details/47777085