aspose file tools*
The moose likes Tomcat and the fly likes How to do Connection Pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to do Connection Pooling" Watch "How to do Connection Pooling" New topic
Author

How to do Connection Pooling

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
Hi,

I am working on a project and i got the complete implementaion to do. I thought to make Connection pooling for JDBC but don't have any idea how to do it (using TomCat) ... can any one of you help me or point me to some nice and detail tutorial, (i don't have much time to search on google and to look for the best tutorial). please help me out.

Regards,


The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Connection pooling implementation varies from container to container.

Since you've told us you're using Tomcat, I'll move this thread to the Tomcat forum for you.
[ August 15, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are two general ways to go about it.

1.) Add a connection pool directly to your app.
See:
http://jakarta.apache.org/commons/dbcp

or

2.) Use container managed connection pooling.
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

Unless you have a real good reason to go with the first, I would recomend starting with the second.
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
thanks, i have an application to be build by 1 week. I am managing the total design architect as well. To handle Database i thought to do Connection Pooling.

I want to ask, should i do for connection pooling or should i make a STATIC DBConnection class, which loads at Server startup and make a connection?
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
One more question, can you suggest me when to choose PreparedStatement and when to use Statement?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Muhammad Ali Amin:
thanks, i have an application to be build by 1 week. I am managing the total design architect as well. To handle Database i thought to do Connection Pooling.

I want to ask, should i do for connection pooling or should i make a STATIC DBConnection class, which loads at Server startup and make a connection?


Your approach will vary according to which of the two options (listed above) you choose. If you're pressed for time, I think the container managed pooling would be the simpler and faster of the two. See the link given for example code.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Muhammad Ali Amin:
One more question, can you suggest me when to choose PreparedStatement and when to use Statement?


We have a forum dedicated to JDBC.
Start a new topic in that forum with this question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to do Connection Pooling