Solved

JSP's, Servlets and Database

Posted on 2001-06-07
3
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

624 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