----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

Hi, 
I have a couple of Java servlets that connect to a database. I wanted them
to all share a database connection instead of each one making their own
database connection each time they run. 

The program should run as follows:

1. Servlet 1 runs and creates a new instance of a class that implements a
HttpSessionBindingListener. 
2. The valueBound method of the HttpSessionBindingListener class connects
to the datbase. 
3. If the user does not use the session for a period of 1 minute, the
session invalidates. 
4. The valueUnbound method of the HttpSessionBindingListener class
disconnects from the database. 
5. Since I have already written a <Meta refresh> tag to the client html
file and set the refresh rate to two minutes, it refreshes after two
minutes to a login page so that the user can log in again and create a new
session.

My valueUnbound method looks like:
----------------------begin code-----------------
     public void valueUnbound(HttpSessionBindingEvent event){

            try {
                  conn.close();
                  conn = null;
            }
            catch(SQLException e){
                  // notify the program
            }
     }
-------------------end code-------------------------

conn.close calls the following method which is in my Database connection
class: 

--------------------code begin--------------------------
public static void close(){
                try {
                        if (resultSet!=null){
                                resultSet.close();
                                resultSet = null;
                     }
                        if (statement!=null){
                                statement.close();
                                statement = null;
                     }
                        if (connection!=null){
                               connection.close();
                                connection = null;
                     }

                }
                catch(SQLException ex) {
                        // notify program       
                }

}
---------------------end code-----------------------------

I have my session timeout for Jserv in the Zone.properties file set to:

session.timeout=60000

which should be one minute. When the session is invalidated, does that mean
that the class that implements HttpSessionBindingListener is imediately
called and that database connection is closed? I am wondering if the
database connection is actually closed. When I check mysql it still shows 2
"Opens" and 2 "Open tables". Is there a better way to do all of this or is
this the preferred method? 

I am using Mysql 3.23.4 - Alpha and ApacheJServ 1.1. 


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to