DRUID连接池:java.sql.SQLRecoverableException: 关闭的语句

本文介绍了在升级DRUID连接池到1.0.29版本后,如何关闭PSCache以避免`java.sql.SQLRecoverableException: 关闭的语句`异常。通过设置`poolPreparedStatements`为`false`和`maxPoolPreparedStatementPerConnectionSize`为`-1`,并提供完整的Spring配置示例。

1、升级1.0.29

2、关闭PSCache.

<property name="poolPreparedStatements" value="false" /> 
  <property name="maxPoolPreparedStatementPerConnectionSize" 
   value="-1" />

==================================

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns=" http://www.springframework.org/schema/beans
 xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:batch=" http://www.springframework.org/schema/batch
 xsi:schemaLocation=" http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

 

 <bean id="propertyConfigure" 
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
  <property name="locations"> 
   <list> 
    <value>./conf/application.properties</value> 
   </list> 
  </property> 
 </bean>

 

 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" 
  init-method="init" destroy-method="close"> 
  <property name="driverClassName" value="${jdbc.driverClassName}" /> 
  <property name="url" value="${jdbc.url}" /> 
  <property name="username" value="${jdbc.username}" /> 
  <property name="password" value="${jdbc.password}" /> 
  <!-- 配置初始化大小、最小、最大 --> 
  <property name="initialSize" value="1" /> 
  <property name="minIdle" value="1" /> 
  <property name="maxActive" value="10" />

  <!-- 配置获取连接等待超时的时间 --> 
  <property name="maxWait" value="10000" />

  <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> 
  <property name="timeBetweenEvictionRunsMillis" value="60000" />

  <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> 
  <property name="minEvictableIdleTimeMillis" value="300000" />

  <property name="testWhileIdle" value="true" />

  <!-- 这里建议配置为TRUE,防止取到的连接不可用 --> 
  <property name="testOnBorrow" value="true" /> 
  <property name="testOnReturn" value="false" />

  <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> 
  <property name="poolPreparedStatements" value="true" /> 
  <property name="maxPoolPreparedStatementPerConnectionSize" 
   value="20" />

  <!-- 这里配置提交方式,默认就是TRUE,可以不用配置 -->

  <property name="defaultAutoCommit" value="true" />

  <!-- 验证连接有效与否的SQL,不同的数据配置不同 --> 
  <property name="validationQuery" value="select 1 " /> 
  <property name="filters" value="stat" /> 
  <property name="proxyFilters"> 
   <list> 
    <ref bean="logFilter" /> 
   </list> 
  </property> 
 </bean>

 

 <bean id="logFilter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter"> 
  <property name="statementExecutableSqlLogEnable" value="false" /> 
 </bean>

</beans>

转载于:https://my.oschina.net/u/151615/blog/3057721

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值