spring with c3p0

参考:(willpower88兄的blog) http://www.blogjava.net/willpower88/archive/2007/01/10/92928.html

当我spring中用c3p0时第一次老出现
org.hibernate.exception.JDBCConnectionException: could not execute query
刷新后就不会。一番折腾后直接用<property name="" value="" />就可以了。随后找到willpower88兄的blog他总结得很好。

环境:
spring 2.0
c3p0-0.9.0.4

spring配置文件如下(引用willpower88兄的,注释掉的都有问题的):

< bean  id ="dataSource"  class ="com.mchange.v2.c3p0.ComboPooledDataSource"    destroy-method ="close" >
         
< property  name ="driverClass"  value ="com.mysql.jdbc.Driver"   />
         
< property  name ="jdbcUrl"  value ="jdbc:mysql://localhost/test" />             
         
< property  name ="user"  value ="root" />
         
< property  name ="password"  value ="" />
          
         
< property  name ="minPoolSize"  value ="2" />
         
< property  name ="maxPoolSize"  value ="20" />
         
< property  name ="maxIdleTime"  value ="1800" />
         
< property  name ="acquireIncrement"  value ="2" />
         
< property  name ="maxStatements"  value ="0" />
         
< property  name ="initialPoolSize"  value ="3" />
         
< property  name ="idleConnectionTestPeriod"  value ="1800" />
         
< property  name ="acquireRetryAttempts"  value ="30" />
         
< property  name ="breakAfterAcquireFailure"  value ="true" />
         
< property  name ="testConnectionOnCheckout"  value ="false" />
         
         
<!--  
         <property name="properties">
          <props>              
              <prop key="c3p0.minPoolSize">1</prop> 
              <prop key="c3p0.maxPoolSize">10</prop> 
              <prop key="c3p0.maxIdleTime">1800</prop>              
              <prop key="c3p0.acquireIncrement">2</prop> 
              <prop key="c3p0.maxStatements">0</prop> 
              <prop key="c3p0.initialPoolSize">2</prop>
              <prop key="c3p0.idleConnectionTestPeriod">1800</prop>
              <prop key="c3p0.acquireRetryAttempts">30</prop>
              <prop key="c3p0.breakAfterAcquireFailure">true</prop>
              <prop key="c3p0.testConnectionOnCheckout">true</prop>
              <prop key="user">root</prop>
              <prop key="password">999999</prop>
              
          </props>
         </property>
        
-->       
</ bean >

<!--  Hibernate SessionFactory  -->
< bean  id ="sessionFactory"  class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  
< property  name ="dataSource"  ref ="dataSource" />
  
< property  name ="mappingDirectoryLocations" >
      
< list >
   
< value > classpath:/com/licaionline/domain/ </ value >
      
</ list >
  
</ property >
  
< property  name ="hibernateProperties" >
   
< props >
     
< prop  key ="hibernate.dialect" > org.hibernate.dialect.MySQLDialect </ prop >
     
< prop  key ="hibernate.show_sql" > true </ prop >
     
< prop  key ="hibernate.generate_statistics" > true </ prop >
     
< prop  key ="hibernate.connection.release_mode" > auto </ prop >                       
     
< prop  key ="hibernate.autoReconnect" > true </ prop >
     
< prop  key ="hibernate.cglib.use_reflection_optimizer" > true </ prop >
<!--  
    <prop key="hibernate.useUnicode"></prop> 
    <prop key="hibernate.characterEncoding"></prop>
    <prop key="hibernate.default-lazy-init"></prop>
    <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>     
 
-->
                                
<!--
    <prop key="hibernate.c3p0.acquire_increment">2</prop>
    <prop key="hibernate.c3p0.idle_test_period">1800</prop>
    <prop key="hibernate.c3p0.timeout">1800</prop>
    <prop key="hibernate.c3p0.max_size">30</prop>
    <prop key="hibernate.c3p0.min_size">2</prop>
    <prop key="hibernate.c3p0.max_statements">50</prop>
-->          
   
</ props >
  
</ property >
</ bean >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值