Solved

JSP's, Servlets and Database

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now