David Salter
Doobries Domain - A blog by David Salter

Doobries Domain - A blog by David Salter

Spring Connection Pooling with DBCP

Photo by Raphaël Biscaldi on Unsplash

Spring Connection Pooling with DBCP

David Salter's photo
David Salter
·Jun 22, 2005·

1 min read

Recently I wanted to add a connection pool to my Spring Web Application. I decided to use Commons DBCP to provide the connection pool as I’m using the Spring JDBC wrapper classes. Googling around didn’t find any examples of how to set up DBCP, so I’ve written my findings here.

Adding a connection pool to a Spring app is simply a matter of specifying the relevant entries in the Spring servlet configuration file. The XML snippet below shows an example of how a database connection pool can easily be configured.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"> 
  <property name="driverClassName"> 
    <value>net.sourceforge.jtds.jdbc.Driver</value> 
  </property> 

  <property name="url"> 
    <value>jdbc:jtds:sqlserver://localhost:1433/db;prepareSQL=0; 
SendStringParametersAsUnicode=False;</value> 
  </property> 
  <property name="username"> 
    <value>username</value> 

  </property> 
  <property name="password"> 
    <value>password</value> 
  </property> 
  <property name="initialSize"> 

    <value>2</value> 
  </property> 
  <property name="maxActive"> 
    <value>5</value> 
  </property> 

  <property name="maxIdle"> 
    <value>2</value> 
  </property> 
</bean>
 
Share this