commons-user mailing list archives

I don't see any problems with the sample code you provided. Based upon
the "connection is closed" message, I'm guessing the problem lies in the
way you're interacting with the JDBC classes. Just to rule out the
obvious, you're not trying to use a PreparedStatement after the Connection
has been closed, are you?
Another possiblity is that you've somehow returned a connection to the
pool more than once, and now two clients are holding onto it (and one
closes it out from under the other). I think there are programatic checks
that prevent that in the recent DBCP builds, but I'm not sure off hand how
recently that was added (i.e., it may have been after the 1.0 release).
On Fri, 27 Dec 2002 sergioboni@bb.com.br wrote:
> 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;
>
> }
>
>
>
> --
> To unsubscribe, e-mail: <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-user-help@jakarta.apache.org>
>
>