MyBatis 配置中那些值得注意的坑
http://blog.csdn.net/hadues/article/details/63686934
Mysql 更改 wait_timeout 配置
http://blog.csdn.net/liuj2511981/article/details/8520912
MySql使用show processlist查看正在执行的Sql语句
https://www.cnblogs.com/jasondan/p/3491258.html
【mybatis】mybatis数据源源码剖析(JNDI、POOLED、UNPOOLED)
http://blog.csdn.net/reliveit/article/details/47325189
show global variables like "%wait_timeout%"; 默认28800 8个小时 ,根据日志错误信息,是上次请求的MySql的连接已经超过MySql的wait_timeout,MySql自动清理超时连接,所以当发起请求时,从配置的数据库连接池中取出来的连接是失效连接,导致报错,解决方法:
因为我使用的是
<dataSource type="POOLED">
直接在数据库配置添加下面代码即可
<!--是否启用侦测查询。若开启,也必须使用一个可执行的 SQL 语句设置 poolPingQuery 属性(最好是一个非常快的 SQL),默认值:false。 -->
<property name="poolPingEnabled" value="true" />
<!--配置 poolPingQuery 的使用频度。这可以被设置成匹配具体的数据库连接超时时间,来避免不必要的侦测,默认值:0(即所有连接每一时刻都被侦测 — 当然仅当 poolPingEnabled 为 true 时适用) 3600000为1个小时-->
<property name="poolPingConnectionsNotUsedFor" value="3600000" />
<!--发送到数据库的侦测查询,用来检验连接是否处在正常工作秩序中并准备接受请求。默认是“NO PING QUERY SET”,这会导致多数数据库驱动失败时带有一个恰当的错误消息。 -->
<property name="poolPingQuery" value="select 1" />
<property name="poolPingEnabled" value="true" />
<!--配置 poolPingQuery 的使用频度。这可以被设置成匹配具体的数据库连接超时时间,来避免不必要的侦测,默认值:0(即所有连接每一时刻都被侦测 — 当然仅当 poolPingEnabled 为 true 时适用) 3600000为1个小时-->
<property name="poolPingConnectionsNotUsedFor" value="3600000" />
<!--发送到数据库的侦测查询,用来检验连接是否处在正常工作秩序中并准备接受请求。默认是“NO PING QUERY SET”,这会导致多数数据库驱动失败时带有一个恰当的错误消息。 -->
<property name="poolPingQuery" value="select 1" />
日志记录错误信息
databases error
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 was43421 milliseconds ago.The last packet sent successfully to the server was 43421 milliseconds ago, which 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 com/dao/IActivationKey.java (best guess)
### The error may involve com.dao.IActivationKey.getActivationKey
### The error occurred while executing a query