This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "connection object into session..." Watch "connection object into session..." New topic
Author

connection object into session...

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi,

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
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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.
Bill


Java Resources at www.wbrogden.com
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: http://aspose.com/file-tools
 
subject: connection object into session...
 
Similar Threads
hibernate
Implementing timeout in JSP
Synchronizing the connection object ?
Destroying java bean and odbc connection
you have got to solve this ...its intersting