C3P0连接问题

时间:2011-03-21 13:44:12

标签: java mysql hibernate connection-pooling c3p0

我正在使用hibernate和cp30进行数据库操作并收到错误:

com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection

以下是我的jdbc属性:

    <property name="acquireIncrement" value="2"/>
    <property name="initialPoolSize" value="6"/>
    <property name="maxIdleTime" value="21600"/>
    <property name="maxPoolSize" value="10"/>
    <property name="maxStatements" value="0"/>
    <property name="minPoolSize" value="2"/>
    <property name="idleConnectionTestPeriod" value="10800"/>
    <!--<property name="testConnectionOnCheckout" value="true" / >-->
    <property name="preferredTestQuery" value="SELECT NOW()"/>
    <property name="maxAdministrativeTaskTime" value="3590"/>
    <property name="unreturnedConnectionTimeout" value="3595"/>
    <property name="debugUnreturnedConnectionStackTraces" value="true"/>

和cp30:

 <prop key="c3p0.acquire_increment">3</prop>
 <prop key="c3p0.idle_test_period">300</prop>
 <prop key="c3p0.max_size">15</prop>
 <prop key="c3p0.max_statements">0</prop>
 <prop key="c3p0.min_size">3</prop>
 <prop key="c3p0.timeout">5000</prop>

Mysql现在没有给我任何连接。有没有办法显示mysql的连接用法?我可以清除这些不良连接吗?最重要的问题是,我该怎么做才能避免这种连接池错误?

提前致谢。

1 个答案:

答案 0 :(得分:0)

数据源是

<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />

        <!--<property name="connectionCustomizerClassName" value="org.xxx.webapp.common.persistence.WatchConnectionCustomizer"/>-->
    <property name="maxStatements" value="500"/>
    <property name="maxIdleTime" value="1800"/>
    <property name="maxPoolSize" value="100"/>
    <property name="minPoolSize" value="2"/>
    <property name="initialPoolSize" value="2"/>
    <property name="acquireIncrement" value="3"/>
    <property name="idleConnectionTestPeriod" value="3000"/>
    </bean>



<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>org.fbis.models.Form21</value>
                <value>org.fbis.models.GSCDetails</value>
                <value>org.fbis.models.DigitalRegistraion</value>                   
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>

    </bean>  

添加hibernate-c3p0-4.2.1.Final.jar