mysql服務端會默認檢查每個連接connection墩莫,一旦發(fā)現(xiàn)connection被閑置8小時(wait_timeout)逞敷,便會被斷開推捐。那我們可以在連接字符串中加入autoReconnect=true,同時配置下mybatis牛柒,一段時間又默認執(zhí)行下簡單的查詢皮壁,表明自己這個連接還活著,具體配置如下:
2015-03-26 09:40:25.956 ERROR GroupPrivController,119 -
Error querying database. Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 57,704,088 milliseconds ago. The last packet sent successfully to the server was 57,704,089 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.
The error may exist in mybatis/hiveDb.xml
The error may involve com.weibo.hamza.core.dao.DbDao.findByOwnerId
The error occurred while executing a query
Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 57,704,088 milliseconds ago. The last packet sent successfully to the server was 57,704,089 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.
org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 57,704,088 milliseconds ago. The last packet sent successfully to the server was 57,704,089 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.
The error may exist in mybatis/hiveDb.xml
The error may involve com.weibo.hamza.core.dao.DbDao.findByOwnerId
The error occurred while executing a query
Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 57,704,088 milliseconds ago. The last packet sent successfully to the server was 57,704,089 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.
[html] view plain copy
<embed id="ZeroClipboardMovie_2" src="http://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" name="ZeroClipboardMovie_2" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=16&height=16" wmode="transparent" width="16" height="16" align="middle">
- <environments default="development">
- <environment id="development">
- <transactionManager type="jdbc"/>
- <dataSource type="POOLED">
- <property name="url" value="${cp.Url}"/>
- <property name="driver" value="${cp.DriverClassName}"/>
- <property name="username" value="${cp.Username}"/>
- <property name="password" value="${cp.Password}"/>
- <property name="poolPingEnabled" value="true"/>
- <property name="poolPingQuery" value="select 1"/>
- <property name="poolPingConnectionsNotUsedFor" value="3600000"/>
- </dataSource>
- </environment>
- </environments>