Database Connection Pooling with Tomcat
Subject:   Old-fashioned article
Date:   2006-04-28 07:54:05
From:   Kunal_Jaggi
Response to: Old-fashioned article

Spring's approach for DBCP is no different from obtaining a DataSource from JNDI (or DI pattern) as shown in the following code snippets.

Spring Code (Enrollment-Config.xml)

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">

<property name="url">



Spring Application Code
public class StudentEnroller implements EnrollAStudent{
private Resource resource;
private BeanFactory factory;
private DataSource ds;
private JdbcTemplate jt;

public StudentEnroller(){
resource=new ClassPathResource("Enrollment-Config.xml");
factory=new XmlBeanFactory(resource);

jt=new JdbcTemplate (ds);

}catch(Exception e){
//log the error

There's nothing earth-shattering here!

Spring provides a choice though, you can inject dependency rather than looking for it.