I obtain a connection using the GenericDatasource as follows

public static Connection getConnection() throws Exception {
        System.out.println("getConnection called");
                
        GenericDataSource dataSource =
(GenericDataSource)servlet.getServletContext().getAttribute(Action.DATA_SOUR
CE_KEY);
        
        org.apache.struts.util.GenericConnection conn = null;
        try 
            {conn = (GenericConnection)dataSource.getConnection();} 
        
        catch (SQLException e) 
            {   //couldn't obtain a connection! FREAK OUT! 
            e.printStackTrace();
            throw new Exception("COULDN'T OBTAIN A CONNECTION FROM THE
POOL!");    
            }
        
        if (conn.isClosed()) //got a closed connection - freak out!
          {throw new Exception("Got a closed connection from the datasource
object!");}
          
          
        
        return conn;
    }
    
----------------------------------------------------------------------------
---------------
it never throws the generic Exception, so presumably it is never returning a
closed connection.
I return connections to the pool as follows:

----------------------------------------------------------------------------
------------------
 public static void releaseConnection(Connection c) {
        try {
                //since this connection was obtained from the pool,
                //calling close() on it should return it to the pool.
                //ensure we are calling close on the wrapper, and not
                //the underlying connection.
                System.err.println("releasing connection of
type:"+c.getClass().getName());
                GenericConnection gc = (GenericConnection)c;
                gc.close();
            } 
        catch (SQLException e) {e.printStackTrace();}
   }
----------------------------------------------------------------------------
--------------------
 - The releaseConnection method always prints out "releasing connection of
type:org.apache.struts.util.GenericConnection"

 - however, if I don't comment out the gc.close() line, I get "connection is
closed" type errors from the JDBC driver. It appears that gc.close()
erroneously closes the "real" connection, instead of .close() simply calling
the wrapper method that returns the connection to the pool?

 - if I comment out the gc.close() line, I must set maxConnections very high
(_really_ high), as expected. But no "connection is closed" errors.

- Any ideas? Anyone else have this problem?

Thanks!
John

-more info-

I'm using a type-4 _certified_ JDBC 2.0 driver

from struts-config.xml...

<data-source 
        autoCommit="false" 
description="ConnectionPool" 
maxCount="500" 
minCount="0" 
driverClass="<a certified JDBC 2.0 driver>" 
password="XX" 
url="<a valid working JDBC URL>" 
type="org.apache.struts.util.GenericDataSource" 
user="YY" 
loginTimeout="99999"/>



Reply via email to