• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle db connections in servlets?

 
Amudha Loganathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rishi Singh
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic