mysql服务端会默认检查每个连接connection,一旦发现connection被闲置8小时(wait_timeout),便会被断开。那我们可以在连接字符串中加入autoReconnect=true,同时配置下mybatis,一段时间又默认执行下简单的查询,表明自己这个连接还活着,具体配置如下:
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>