Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Using JDBC in JSP Sessions

Thread view: 
Clive Backham - 08 Oct 2007 13:55 GMT
I'm in the early stages of experimenting with JSP talking to
databases. (I'm not sure if this is the correct newsgroup for
questions on this subject. If not, could someone suggest a better
group to try?)

All the examples I've come across so far show a database connection
being made, used, and closed in a single page. In the course of my
experiments, I've determined that the database connection can be saved
as a session attribute and remains available to other pages in the
application without the need to re-establish the database connection
on each page. This clearly has some performance advantages.

The question is: is this regarded as acceptable? Obviously I can close
the connection if the user of the web application explicitly issues a
logout of some sort. But what if they just leave the website? Is it OK
to rely on the garbage collector to close the database connection when
the session itself gets timed out?
Lew - 08 Oct 2007 15:12 GMT
> I'm in the early stages of experimenting with JSP talking to
> databases. (I'm not sure if this is the correct newsgroup for
[quoted text clipped - 7 lines]
> application without the need to re-establish the database connection
> on each page. This clearly has some performance advantages.

You mean disadvantages.  How many connections does your database support?  How
many users would you like to support?  How is your thread safety?

> The question is: is this regarded as acceptable?

"regarded", not relevant.  "acceptable" by what criteria?  It's a complicated,
unscalable and bug-prone approach, for what that's worth.

> Obviously I can close the connection if the user of the web application explicitly issues a
> logout of some sort. But what if they just leave the website? Is it OK
> to rely on the garbage collector to close the database connection when
> the session itself gets timed out?

No, because the garbage collector (GC) doesn't close connections, and you
can't even be sure it'll release the connection object.

Don't put connections in the session.  Use a pooling driver.

Signature

Lew

Clive Backham - 08 Oct 2007 15:40 GMT
Thanks for your forthright response.

> Don't put connections in the session.  Use a pooling driver.

Ah, right. I hadn't got as far as connection pooling yet. Sorry for
asking a dumb question.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.