commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward Q. Bridges" <ebrid...@citco.com>
Subject [DBCP] Help with PreparedStatement pooling
Date Fri, 18 Feb 2005 23:47:50 GMT
Hi, I'm quite confused about how to get prepared statement pooling to work.

This is the code I'm workign with:

        ConnectionFactory connFactory = new DriverManagerConnectionFactory(
                cfg.getUrl(),
                cfg.getUsername(),
                cfg.getPassword()
        );

        ObjectPool connPool = new GenericObjectPool(null, cfg.toConfig());
        KeyedObjectPoolFactory stmtPoolFactory = new 
GenericKeyedObjectPoolFactory(null);

        PoolableConnectionFactory x = new PoolableConnectionFactory(
                connFactory,
                connPool,
                stmtPoolFactory,
                cfg.getValidationQuery(),
                cfg.isDefaultReadOnly(),
                cfg.isDefaultAutoCommit(),
                cfg.getDefaultTransactionIsolation()
        );

        DataSource ds = new PoolingDataSource(connPool);

And when I run this, I'm getting an assertion failed when i retrieve two 
prepared statements for the same connection.

    assertEquals(stmt, stmt2);
    junit.framework.AssertionFailedError:
       
    expected:<org.apache.commons.dbcp.DelegatingPreparedStatement@17a8a02>
        but
    was:<org.apache.commons.dbcp.DelegatingPreparedStatement@1b3f829>


    assertEquals(((DelegatingPreparedStatement)stmt).getInnermostDelegate(),
                  
    ((DelegatingPreparedStatement)stmt2).getInnermostDelegate());
    junit.framework.AssertionFailedError:
        expected:<com.sybase.jdbc2.jdbc.SybPreparedStatement@5a9de6>
        but was:<com.sybase.jdbc2.jdbc.SybPreparedStatement@10da5eb>

What should I be expecting on this?  How would I tell that the pooling 
is working correctly with PreparedStatements?
Can someone point out what I'm doing wrong above?

Thanks in advance
Ed Bridges





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message