• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database connection management

 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...!!

I need your opinion regarding the database management in web-app

which one is best approach and why or suggest me any better approch

either to make single database connection and set that in session

or to make new database connection for each request and then close that connection as soon as request is completed

Thanks in advance
Ramandeep S
 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the web-app, I guess you must be using data source to get the connection. Are you using any jdbc framework like spring/hibernate?
 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

Thanks for your reply first

No i m not using any of the frameworks

Thanks
Ramandeep S
 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, I would suggest to use one connection for one transaction. So essentially transaction can not be spanned across multiple sessions but certainly it can span across multiple requests.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, I would suggest to use one connection for one transaction. So essentially transaction can not be spanned across multiple sessions but certainly it can span across multiple requests.

It's possible you mean the right thing, but the wording as it is is not correct (or at the least highly misleading). Transactions really do not figure into this. The usual way to do this would be to maintain a DB connection pool for the web app, and then to obtain a connection from it if a request comes in that needs DB access. After the request is completed, the connection should be returned to the pool. Open connections should *not* be stored in sessions - you'd run out of connections pretty quickly.
 
rohith das
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#You may create a main method for connection.
#from that you may please inherit to the DAo classes

I think this is one good approach

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic