`
haiziwoainixx
  • 浏览: 409903 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

c3p0连接池使用问题

阅读更多

前段使用C3P0连接池连接数据库,其中遇到一问题,服务器每过一段时间便会报错:

 

2014-09-04 17:08:18 ERROR [resin-port-8080-30902] [TrendTouchServiceImpl] TrendTouchService uploadPhotoTrend error: org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL [**** ]; Communications link failure

Last packet sent to the server was 2 ms ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

查了一下,这个问题是因为连接池中的连接失效,而应用直接拿来使用,没有对连接进行检查造成的,解决方案:

 

在连接池配置中加入以下两个参数:

<property name="testConnectionOnCheckout" value="true"/>
<property name="preferredTestQuery" value="select 1"/>

问题解决! 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics