File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Databse session and web session issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Databse session and web session issue" Watch "Databse session and web session issue" New topic

Databse session and web session issue


Joined: Dec 02, 2003
Posts: 10
I wish to know whether a database session can be terminated earlier than web session which is binding the database session. The database session is bound to the web session upon database login by:
1. javax.servlet.http.HttpSessionBindingListener;
2. javax.servlet.http.HttpSessionBindingEvent;
Both the database session and web session are set to timeout in 60 minutes.
When we do an experiment to manually terminate the database session after 30 minutes, our expected result is that no record can be added to the database from the web application after 30 minutes. We test this because there is a possiblility that the database session may end earlier than web session for unknow reason.
But our test result shows that record still can be added to database after 30 minutes.
1. What is the cause of this unexpected result ?
2. What is the supposed result ?

Thanks in advance.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Not a beginner's question. Moving to servlets.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I'm puzzled by what you are doing here. You say The database session is bound to the web session upon database login. Do you mean that a JDBC Connection is created when a user logs in to the web application? If so, where do you store this Connection object, and how do you use it?
Can you please explain in a bit more detail how you access your database from your Java code?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

"Wkw Kent"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
Thanks! and welcome to the JavaRanch!

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Here is my wild guess.
You have bound the Connection object to the Session, which I don't see how you do this, but anyway, as with JNDI, you bound a reference to the object is a "HashMap" of some sort, and that reference is still there, therefore the object is still active and can be used. You would have to unbind the object so that there are no references to it anywhere in order to make sure that you destroy that object and it is no longer available.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Sorry, but I have my architect hat on here. If you need a database connection, I think your current route is the bad way to go. I would think you would won't some Connection pool sitting on the server waiting to give connections out when they are needed only. Not all the time. Meaning when you web application needs to do something to the database, then it gets the Connection object from the pool, uses it and then sends it back to the pool. Using a J2EE server, you have DataSources, and Connection Pools built into the server, so that you don't have to do much work to use it.
But I have been wrong before.
I agree. Here's the link:
subject: Databse session and web session issue
It's not a secret anymore!