aspose file tools*
The moose likes JDBC and the fly likes Question on Best Practice for Database Connections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Question on Best Practice for Database Connections" Watch "Question on Best Practice for Database Connections" New topic
Author

Question on Best Practice for Database Connections

Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
Hi,

What is the best practice when utilizing a WebSphere connection pool? Currently, a application that I am working on, opens a connection when needed and passes the object to the Data Access Object which then closes the connection when it is finished with it. Would it be better to open ONE connection and store it in a session, that way all DAOs can access it whenever needed?

Thanks,
Lulu
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
In general, get a connection only when you need it, then return it to the pool as soon as you are finished with it.
Rene Smith
Greenhorn

Joined: Jun 10, 2004
Posts: 21
I would not store the connection in a session. Depending on your site you probably do not want a connection hanging open that long
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to JDBC...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I would suggest don't put connection in session. Create a datasource in websphere make connection from datasource when you need and close it as soon as you are done.

rest leave on websphere.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Best Practice for Database Connections