commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sergiob...@bb.com.br
Subject How to Pooling preparedStatements
Date Fri, 27 Dec 2002 22:00:37 GMT
Hi,

 I am using the dbcp package to pool my connections in our intranet.
 It works very, very well with regular statements but i can't do it work
with preparedStatements.
Below is the method that i use. When i try to get a prepStatement i receive
this:

"Connection is closed".

Where is the mistake?

Thanks,

Sérgio Bonifácio.

public DataSource setupDataSource(DBAlias alias)throws Exception {

     GenericObjectPool connectionPool = new GenericObjectPool(null);
     connectionPool.setMaxActive(alias.getMaxConexoesSimultaneas());
     connectionPool.setMaxIdle(alias.getMaxConexoesOciosas());

     //classe para possibilitar o uso de preparedStatements pelo pool
     StackKeyedObjectPoolFactory stmPoolFactory = new
StackKeyedObjectPoolFactory();

     ConnectionFactory connectionFactory =
          new DriverManagerConnectionFactory(
                         alias.getURIConexao(),
                         alias.getUser(),
                         alias.getSenha());

     PoolableConnectionFactory poolableConnectionFactory =
          new PoolableConnectionFactory(
                         connectionFactory,
                         connectionPool,
                         stmPoolFactory,
                         null,
                         false,
                         true);


     //obtem o data source do objectPool
     PoolingDataSource dataSource =      new
PoolingDataSource(connectionPool);

     System.out.println("Pool "+alias.getNomeAlias()+" configurado:");
     System.out.println("maximo de conexoes ativas: "+
alias.getMaxConexoesSimultaneas());
     System.out.println("maximo de conexoes ociosas: "
+alias.getMaxConexoesOciosas());

     return dataSource;

}


Mime
View raw message