File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to handle db connections in servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to handle db connections in servlets?" Watch "How to handle db connections in servlets?" New topic
Author

How to handle db connections in servlets?

Amudha Loganathan
Greenhorn

Joined: May 20, 2002
Posts: 6
Hi,
How to efficiently handle db connections in servlets deployed in WAS4.0?
In servlet init method I am opening the connection and I am closing it in the destroy method ?
Is it correct ?
TAI,
Amudha


TAI,<br />Amudha L
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I don't know if Websphere does it's own connection pooling. You may want to look into it though. Since it means that several hits to you servlet will share the same connection.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rishi Singh
Ranch Hand

Joined: Dec 09, 2000
Posts: 321
Hi,
For a DB connection pool initialization the best means would be as
follows in decreasing order of preferance
1. Context Initialization
2. init() method
3. initialization on the receiving the first request.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Use a DataSource. IBM has a good example of setting this up at Advanced application assembly and deployment tutorial
Once it's configured for your server, any example code for using a Connection from a DataSource will work.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to handle db connections in servlets?