Eric,

I've tried similar things as you but I couldn't get it to work either.  My
work around was writing a Utility class that return an javax.sql.DataSource
object and then use Apache Commons DPCP and the Pool.

Something like this:

public class DBUtil {
        /**
         * Create a PooledDataSource with properties specified in
<CODE>props</CODE>
         * 
         * @return
         */
    public DataSource getDataSource(Properties props) 
    {
                final DriverAdapterCPDS cpds = new DriverAdapterCPDS();
                try
                {
                        cpds.setDriver( props.getProperty("driver") );
                }
                catch ( ClassNotFoundException e )
                {
                        logger.fatal("DB Driver not found: " +
e.getMessage() );
                        return null;
                }
                cpds.setUrl( props.getProperty("url") );
                String userName = props.getProperty("username",
System.getProperty("user.name") );
                if ( userName!=null ) cpds.setUser(
props.getProperty("username") );
                String pw = props.getProperty("password");
                if ( pw != null ) cpds.setPassword( pw );
                
                /**
                 * Apache PooledDataSource
                 */
                final SharedPoolDataSource tds = new SharedPoolDataSource();

                
                tds.setConnectionPoolDataSource(cpds);
                String maxPoolSize = props.getProperty("maxPoolSize");
                if ( maxPoolSize != null )
                {
                        int size =  Integer.parseInt(maxPoolSize);
                        //cpds.setMaxActive( size );
                        tds.setMaxActive( size );
                }
                
                String maxIdleSize = props.getProperty("maxIdleSize");
                if ( maxIdleSize != null ) 
                {
                        tds.setMaxIdle( Integer.parseInt(maxIdleSize));
        } 
                
                String minEvictableIdleTimeMillis =
props.getProperty("minEvictableIdleTimeMillis");
                if ( minEvictableIdleTimeMillis != null ) 
                {
                        tds.setMinEvictableIdleTimeMillis(
Integer.parseInt(minEvictableIdleTimeMillis) );
                } 
                
                String poolTimeOut = props.getProperty("poolTimeOut");
                if ( poolTimeOut != null ) 
                {
                        tds.setMaxWait( Integer.parseInt(poolTimeOut) );
        } 
                String timeBetweenEvictionRunsMillis =
props.getProperty("timeBetweenEvictionRunsMillis");
                if ( timeBetweenEvictionRunsMillis != null )
                {
                        cpds.setTimeBetweenEvictionRunsMillis(
Integer.parseInt(timeBetweenEvictionRunsMillis)); 
                        tds.setTimeBetweenEvictionRunsMillis(
Integer.parseInt(timeBetweenEvictionRunsMillis));
                }
                String numTestsPerEvictionRun =
props.getProperty("numTestsPerEvictionRun");
                if ( numTestsPerEvictionRun != null )
                {
                        tds.setNumTestsPerEvictionRun(
Integer.parseInt(numTestsPerEvictionRun) );
                        cpds.setNumTestsPerEvictionRun(
Integer.parseInt(numTestsPerEvictionRun) );
            }
                String testWhileIdle = props.getProperty("testWhileIdle",
"false");
                tds.setTestWhileIdle( Boolean.getBoolean(testWhileIdle));
                String validationSQL =
props.getProperty("validateStatement");
                if ( validationSQL != null ) tds.setValidationQuery(
validationSQL );
                String validateOnCheckout =
props.getProperty("validateOnCheckout");
                if ( validateOnCheckout != null ) tds.setTestOnBorrow(
Boolean.getBoolean(validateOnCheckout) );

                logger.info( "DB Pool created: " + tds);
                logger.info( "URL=" + props.getProperty("url") );
                logger.info( "maxPoolSize=" + tds.getMaxActive() );
                logger.info( "maxIdleSize=" + tds.getMaxIdle() );
                logger.info( "maxIdleTime=" +
tds.getMinEvictableIdleTimeMillis() + "ms" );
                logger.info( "poolTimeout=" + tds.getMaxWait() );
                logger.info( "timeBetweenEvictionRunsMillis=" +
tds.getTimeBetweenEvictionRunsMillis() );
                logger.info( "numTestsPerEvictionRun=" +
tds.getNumTestsPerEvictionRun() );
                
        return tds;
    }
}

There are also examples at the Apache Jakarta site. 

Hope that helps.

--Hien

-----Original Message-----
From: Eric SCHULTZ [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 13, 2003 10:17 AM
To: Struts Users Mailing List (E-mail)
Subject: DB2 Pooled connection from Struts


Good morning...

I'm having an impossible time getting a pool of connections to a DB2
database going.

I've gotten a single connection to work using the old method
(DriverManager.register, DriverManager.getConnection, ...) but I can't seem
to do it by describing the datasource in struts-config.xml and calling
getDataSource().

Here's the code that works (in a bean):
        DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
        Connection conn = DriverManager.getConnection("jdbc:db2:DB2Test",
"user", "password");

I've tried a whole bunch configurations in struts-config.xml, for example:
        <data-source key="CIS"
type="COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource">
                <set-property property="driverClass"
value="COM.ibm.db2.jdbc.app.DB2Driver" />
                <set-property property="url" value="jdbc:db2:DB2Test" />
                <set-property property="user" value="user" />
                <set-property property="password" value="password" />
                <set-property property="maxActive" value="10" />
                <set-property property="maxWait" value="5000" />
                <set-property property="defaultAutoCommit" value="false" />
        </data-source>

and then in my Action I call:
        CISCustomerLookup ccl = new CISCustomerLookup(getDataSource(req,
"CIS").getConnection());

Where ccl is my bean and to shield it from the Struts layer I pass the
connection it should use for the lookup.  But it doesn't work.  The latest
error I recieved is the following:
        javax.servlet.ServletException: [IBM][JDBC Drvier] CLI0615E Error
receiving from...

I've also recieved messages alluding to no suitable driver available.  And
when I check the Tomcat log I have often had a situation where the
ActionServlet was marked unavailable due to a problem creating the
datasource when I deployed the war.

 I've also tried the net driver (COM.ibm.db2.jdbc.net.DB2Driver) with
similar results.

Help me please!!!  Any working examples would be most apprciated.

Eric Schultz
Technical Leader
Conseiller Technique
Elix
Specialist in interactive business solutions
Specialiste en solutions d'affaires interactives
14 Commerce Place, 5th floor
Nun's Island, QC  H4E 1T5
t: 514 768-1000
f: 514 768-7680


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to