Solved

JSP's, Servlets and Database

Posted on 2001-06-07
3
255 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

776 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