org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.JDBC中url的问题

一个定时任务每天晚上三点执行一遍,第一天没问题,第二天就开始出问题了,日志报这个错误,

### The error may exist in mapper/LogMapper.xml
### The error may involve mapper.LogMapper.getHotelMessage
### 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 was86394 milliseconds ago.
The last packet sent successfully to the server was 86394 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.

 

百度后说是mysql 有一个侦测的机制,8小时的连接没有动作,就会认为是死的,就会出现以上错误,所以要配置一个定时查询,小于8小时,最好简单一点,我用的mybatis  有一个配置直接配上就行了。

在jdbc 的url  中开启  autoReconnect=true  


    <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> 


poolPingEnabled  、 poolPingQuery  、 poolPingConnectionsNotUsedFor  开启就可以了,

然后我在配置这个url 的时候xml  提示报错,就是以下的问题  有一个转义的问题

 

The reference to entity "autoReconnect" must end with the ';' delimiter.这个是因为xml中有转移字符

错误的写法

value="jdbc:mysql://127.0.0.1:3306/CCCXXX?characterEncoding=utf-8&autoReconnect=true" />

正确的写法

value="jdbc:mysql://127.0.0.1:3306/72byte_cloud?characterEncoding=utf-8&amp;autoReconnect=true" />

xml中的转义字符

&lt;

<

小于号

&gt;

>

大于号

&amp;

&

&apos;

'

单引号

&quot;

"

参考https://blog.csdn.net/hanye0204856/article/details/12998477  

    https://blog.csdn.net/huanggang028/article/details/44646387

https://blog.csdn.net/hanye0204856/article/details/12998477 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值