Announcement Announcement Module
Collapse
No announcement yet.
Configuring C3P0 Datasource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring C3P0 Datasource

    Hi.

    [c3p0 0.9.0 / Spring 1.1.5]

    I've tried to configure c3p0 as a datasource using the ComboPooledDataSource class, but some how my properties won't bite:

    Code:
    <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="driverClass"><value>org.hsqldb.jdbcDriver</value></property>
            <property name="jdbcUrl"><value>jdbc&#58;hsqldb&#58;mem&#58;aname</value></property>
            <property name="user"><value>sa</value></property>
            <property name="password"><value></value></property>
            <property name="properties">
                <props>
                     <prop key="c3p0.acquireRetryAttempts">5</prop>
                </props>
            </property>
        </bean>
    When using the above datasource the 'acquireRetryAttempts' is set to the default: 30.

    So, I've managed to set up Spring and c3p0 using an alternative approach. It works, but feels a bit verbose:

    Code:
    <!-- Configure the c3p0 datasource -->
        <bean id="poolConfig" class="com.mchange.v2.c3p0.PoolConfig">
            <property name="acquireRetryAttempts"><value>10</value></property>
            <property name="acquireRetryDelay"><value>1000</value></property>
            <property name="automaticTestTable"><value>C3P0_TEST_TABLE</value></property>
            <property name="checkoutTimeout"><value>10000</value></property>
            <property name="idleConnectionTestPeriod"><value>10</value></property>
            <property name="maxPoolSize"><value>20</value></property>
            <property name="maxStatements"><value>200</value></property>
            <property name="maxStatementsPerConnection"><value>20</value></property>
        </bean>
    
        <!-- Register the database driver -->
        <bean id="driverClass" class="java.lang.Class" factory-method="forName">
            <constructor-arg><value>$&#123;jdbc.driver&#125;</value></constructor-arg>
        </bean>
        <bean id="driverInstance" class="java.lang.Class" factory-method="newInstance" factory-bean="driverClass" depends-on="driverClass" />
    
        <!-- Create the c3p0 unpooled ds -->
        <bean id="unpooledDataSource" class="com.mchange.v2.c3p0.DataSources" factory-method="unpooledDataSource" depends-on="driverInstance" >
            <constructor-arg index="0"><value>$&#123;jdbc.url&#125;</value></constructor-arg>
            <constructor-arg index="1"><value>$&#123;jdbc.user&#125;</value></constructor-arg>
            <constructor-arg index="2"><value>$&#123;jdbc.password&#125;</value></constructor-arg>
        </bean>
    
        <!-- Create the pooled data source to actually use -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.DataSources" factory-method="pooledDataSource" depends-on="unpooledDataSource">
            <constructor-arg><ref local="unpooledDataSource"/></constructor-arg>
            <constructor-arg><ref local="poolConfig"/></constructor-arg>
        </bean>
    Any comments on the above? How are you doing it?

    //Anders

  • #2
    Search the forums and see the spring samples. This thread for example:

    http://forum.springframework.org/showthread.php?t=16309
    Last edited by robyn; May 16th, 2006, 04:17 AM.

    Comment


    • #3
      Originally posted by costin
      Search the forums and see the spring samples. This thread for example:

      http://forum.springframework.org/showthread.php?t=16309
      Thanks for the reply.

      I did search the forums, and I found that post. But that configuration doesn't work (for me). See my first example - it's more or less taken from that post.

      The ComboPoolDataSource won't use the properties I pass to it :/
      Last edited by robyn; May 16th, 2006, 04:17 AM.

      Comment


      • #4
        See what version of c3p0 you have and read the javadocs for that version - I had some problems in the past where they changed the property names and after an upgrade the configuration was simply ignored.
        My guess is that either your property names are incorrect or somehow your properties get rewritten.

        Comment


        • #5
          Originally posted by costin
          See what version of c3p0 you have and read the javadocs for that version - I had some problems in the past where they changed the property names and after an upgrade the configuration was simply ignored.
          My guess is that either your property names are incorrect or somehow your properties get rewritten.
          Thanks for the suggestion.

          I've checked the JavaDoc (and the source code) and it looks like I'm using the right property names (0.9.0).

          I'll keep using my "verbose" setup for a while though. Besides being verbose - can anyone see any other problems with that approach (second XML block in the original post)?

          Comment

          Working...
          X