Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Best Practice for Database Connections

 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC...
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic