| Article: |
Database Connection Pooling with Tomcat | |
| Subject: | Old-fashioned article | |
| Date: | 2006-04-27 06:24:15 | |
| From: | sorend | |
|
I think this article is little behind current pace.
|
||
Showing messages 1 through 2 of 2.
-
Get away with Spring/Hibernate
2006-04-27 22:04:13 JasonSherman [View]
-
Old-fashioned article
2006-04-28 07:54:05 Kunal_Jaggi [View]
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)
-------------------------------------
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/dbcptest</value>
</property>
</bean>
</beans>
Spring Application Code
------------------------------
public class StudentEnroller implements EnrollAStudent{
private Resource resource;
private BeanFactory factory;
private DataSource ds;
private JdbcTemplate jt;
public StudentEnroller(){
try{
resource=new ClassPathResource("Enrollment-Config.xml");
factory=new XmlBeanFactory(resource);
ds=(DataSource)factory.getBean("dataSource");
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.



With regard to this article, it’s targeted towards small to medium size applications which have a small footprint and don’t require a heavyweight EJB container. I think we must give some credit to the author, cause towards the end, he does mention about out-of-box connection pooling features available in peculiar J2EE environment. Moreover, there are good numbers of developers who are just happy with a simple servlet container like Tomcat and want to explore more into it.