6

I am using spring and hibernate stand-alone applications. I am using below configuration.

<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${driverClassName}" />
        <property name="url" value="${db.url}" />
        <property name="username" value="${db.username}" />
        <property name="password" value="${db.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.some.SomePojo</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${mdm.db.dialect}</prop>

            </props>
        </property>
    </bean>


    <tx:annotation-driven transaction-manager="transactionManager" />

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

Is DriverManagerDataSource opens up a database connection every time data is requested? or does it reuses already opened connection? Also, does it close idle connections? to make use of the connection pooling concept do I need c3p0?

Thanks!

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
user1016403
  • 12,151
  • 35
  • 108
  • 137
  • http://stackoverflow.com/questions/4961173/how-to-reuse-the-same-connection-with-a-springs-jdbctemplate – coderz Dec 08 '15 at 01:40

1 Answers1

6

The java doc states;

This class is not an actual connection pool; it does not actually pool Connections.

See for more info

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/jdbc/datasource/DriverManagerDataSource.html

Mark Bakker
  • 1,278
  • 8
  • 19
  • Thanks for your reply. Can i use c3p0 in a stand alone application? or it should be used in web applicaton? bcaz my appln is not deployed in any application server. Thanks! – user1016403 Jul 16 '12 at 08:50
  • You have 3 options; 1 use the container based connection pooling JNDI, 2 use c3po, or 3 DBCP. i would go for option 1 it keeps your spring config more simple – Mark Bakker Jul 16 '12 at 08:54