It's not a secret anymore!
The moose likes Servlets and the fly likes connection object into session... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "connection object into session..." Watch "connection object into session..." New topic

connection object into session...

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830

I am using JDBC in a web project. Many user can access the site at the same time. I don't know much about connection pooling, I just heard the term. So I thought this new approach:

I will create a connection object for each user at first visit of user and set it into session attribute of that user and whenever this user will perform some kind of database operation, I will get the same connection object from session and use it....

Please tell me, how is this approach...
Any major drawback???

Thanks a lot.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
Any major drawback???

Many major drawbacks - right offhand I can think of:
1. If the site is at all busy you will open MANY more connections than you need and may run into a limit imposed by the database.
2. Every user will experience an extra delay as the connection is opened (as opposed to a minium delay with a connection pool).
3. If the database side closes a Connection the session will be unusable.
You should expend you energy in understanding how connection pools work.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
If you are using Tomcat, which is the most likely, then you can look into DBCP.
I agree. Here's the link:
subject: connection object into session...
It's not a secret anymore!