views:

33

answers:

2

Hi All,

Can somebody help me setup connection pooling in Spring MVC. Later next month, I will release my first local intranet website powered by Spring MVC 2.5 and Jquery. This is my first attempt at web development =)

I am not sure but, I am only using this in my spring configuration file and I saw this in the Spring MVC step By Step tutorial

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  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}" />
 </bean>

 <bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
    <value>classpath:jdbc.properties</value>
   </list>
  </property>
 </bean>

This looks good during development and connection speed is fast but I am not sure if this will still holds true if many users are concurrently connected.

Can you share me some links or step by step tutorial please. I have read that this is not an optimal connection datasource. Thank you

+1  A: 

You might want to look at c3p0, which has some powerful configuration and optimization available.

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="..." />
    <property name="jdbcUrl" value="..." />
    <property name="user" value="..." />
    <property name="password" value="..." />
</bean>
James Earl Douglas
@James. As a new Spring Developer, I havent heard about this C3PO thing. But as I googled the net, I found some interesting discussion about this. One question though to clear my thoughts, If I create a bean like the one you have given above and then add the required C3PO jar file in my build path, can I say say that I am doing connection pooling already? Thanks
Mark Estrada
"If I create a bean like the one you have given above and then add the required C3PO jar file in my build path, can I say say that I am doing connection pooling already?"Yes you can, though you could say the same with BasicDataSource (it uses commons-pool).
James Earl Douglas
A: 

Your current setup is correct, all you need to do in order to use basic connection pooling is use a DataSource implementation provided by a connection pooling library, in your case Apache DBCP. See this post for a few links to other alternatives, C3P0 being one of them.

Note that when you actually use the DataSource bean you're injecting wrap it in a SimpleJdbcTemplate or use DataSourceUtils to obtain a Connection - see Spring JDBC Documentation

Jon Freedman