Solved

JSP's, Servlets and Database

Posted on 2001-06-07
3
263 Views
Last Modified: 2013-11-24
When developing a Web application that uses databases in either JSP's or Servlets is it good practice to open the connection to the database in every Servlet or JSP that requires a database connection or would it be more appropriate to manage all database access via a bean ?

If it is best to manage all database access via a bean would it be appropriate to store this bean in the session object (so that it is created for each user session) or would it be more appropriate to store it in the application object ?  My concern here is related to the overhead of opening many connections to a database.

I would be grateful for all advice offered regarding this.

Thanks in advance

John
0
Comment
Question by:johnclarke
3 Comments
 
LVL 3

Expert Comment

by:chrisos
ID: 6163103
The method I use to to use a bean that manages a connection pool for the database.

The bean resides at an aplication level, so the pool is always available.

By using a pool, you only have the overhead required to create the initial connections and any additional connections when the pool runs out.  In return you get good performance from your requests when the pool can service the request.

Regards,

Chrisos
0
 

Accepted Solution

by:
dwhitake earned 50 total points
ID: 6166282
A connection pool is definitly the best way to go.  It makes db access simpler by keeping track of all your connections for you.  There us a free connection pool available at:  http://www.javaexchange.com

I have used it before and it works really well.  You can also specify parameters to it that let you customize the initSize and maxSize of your connection pool, so you don't have to worry about too few or too many connections open at one time.

Hope this helps,
David
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6777984
johnclarke--->  You logged in recently, but did not update/finalize your open questions.  Please do.

If you've been helped, please accept the expert comment which helped you to grade and close it.  If you need help splitting points between multiple experts, comment with detail.

I will post this in all your open questions and monitor them for closure.  Please check the HELP DESK link on the left for site-related information on the Question/Answer process, Guidelines and Member Agreement.

Expert input is always welcome to determine the fair outcome of this question in the event johnclarke does not respond.

Thanks all,

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question