Mysql autoReconnect 問題com.mysql.jdbc.CommunicationsException
2024-07-24 12:58:41
供稿:網友
前段時間使用Hibernate + MySQL遇到了這個問題com.mysql.jdbc.CommunicationsException : 。。。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. , x q
查了一下終于解決了這個問題,原來是mysql超時設置的問題
具體解決方法:
方法一:使用hibernate 修改Hibernate.cfg.xml加入一下參數
<property name="connection.autoReconnect">true</property> rVQw
<property name="connection.autoReconnectForPools">true</property> CwvgnlI?
<property name="connection.is-connection-validation-required">true</property> 42LtkTOw
方法二:不是也hibernate 修改數據庫連接參數
數據庫連接參數中加入autoRcConnect=true
connection url加參數: autoReconnect=true =h6yD*%
方法三:是也C3P0
<property name="hibernate.c3p0.acquire_increment">1</property> ba,oxjR/a
<property name="hibernate.c3p0.idle_test_period">0</property> jUTE)lO&}
<property name="hibernate.c3p0.timeout">0</property> ]g11Q^3;
<property name="hibernate.c3p0.validate">true</property>
這樣就可以解決問題。
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/zm12037/archive/2009/12/30/5109240.aspx