I don't see anything wrong with your code after a quick look.
One possibility I think is that, assuming you are using a non-xa db driver,
the connection will not be returned to the pool until the transaction is
over, so the pool can always supply the same connection for all work in one
transaction. Is there any chance two methods are being called in one
transaction, and this is the first?
thanks
david jencks
On 2001.11.19 16:38:46 -0500 Edson Carlos Ericksson Richter wrote:
> I'm getting in trouble with JDBC Pool.
> After all use of a connection, I close resultSet, I close the statement
> and
> then close Connection.
> After all closes I get "returned object", except in one case. If anyone
> can
> analyse this code and give some idea, please do:
>
> public List getAll() throws RemoteException {
> ArrayList lista = null;
> Connection connection = null;
> Statement statement = null;
> ResultSet resultSet = null;
> MyObject tipo = null;
>
> try {
> StringBuffer sql = new StringBuffer( "select co_tipo, ds_tipo
> from tipo order by co_tipo" );
> connection = this._getConnection( ); // this method returns
> one
> connection from the pool.
>
> statement = connection.createStatement( );
> resultSet = statement.executeQuery( sql.toString( ) );
> tipo = null;
>
> lista = new ArrayList( );
>
> while( resultSet.next( ) ) {
> try {
> tipo = new MyObject( );
> tipo.codigo = resultSet.getInt( 1 );
> tipo.descricao = resultSet.getString( 2 );
> } catch( Exception e ) {
> e.printStackTrace( );
> }
>
> lista.add( tipo );
> }
> } catch( Exception e ) {
> e.printStackTrace();
> lista = null;
> } finally {
> this._close( connection, statement, resultSet ); //this
> method
> closes, in order, ResultSet, Statement and then Connection
> }
>
> return lista;
> }
>
> private void _close( Connection connection, Statement statement,
> ResultSet resultSet ) {
> if( _DEBUG )
> System.out.println("_close( Connection, Statement, ResultSet )"
> );
>
> if( resultSet != null ) {
> try {
> resultSet.close( );
> } catch( Exception e ) {
> e.printStackTrace( );
> }
> }
>
> if( statement != null ) {
> try {
> statement.close( );
> } catch( Exception e ) {
> e.printStackTrace( );
> }
> }
>
> if( connection != null ) {
> try {
> connection.close( );
> } catch( Exception e ) {
> e.printStackTrace( );
> }
> }
> }
>
> private Connection _getConnection( ) {
>
> DataSource dataSource = null;
> Connection connection = null;
>
> try {
> javax.naming.Context context = new
> javax.naming.InitialContext( );
>
> try {
> dataSource = ( DataSource )context.lookup(
> "java:/jdbc/myDB" );
> } catch( Exception e2 ) {
> e2.printStackTrace();
> throw new EJBException( "Erro buscando o DataSource: " +
> e2.toString( ) );
> }
>
> try {
> connection = dataSource.getConnection( );
> } catch( Exception e2 ) {
> e2.printStackTrace();
> throw new EJBException( "Erro buscando Connection: " +
> e2.toString( ) );
> }
>
> } catch( Exception e1 ) {
> e1.printStackTrace();
> throw new EJBException( "N�o foi poss�vel obter o \"Initial
> Context\": " + e1.toString( ) );
> }
>
> return connection;
> }
>
>
> I have several other methods that works exactly same way, but they closes
> connection when I call _close in finally clause...
> Maybe this a JDBC Pool bug? Setting connection time out in JCML
> configuration file does not release connection nevermore...
>
> Anyone can give a light?
>
>
> Thanks,
>
>
> Edson Richter
>
> ----- Original Message -----
> From: "David Jencks" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, November 19, 2001 4:55 PM
> Subject: Re: [JBoss-user] JDBC Pool
>
>
> > On 2001.11.19 14:34:06 -0500 Edson Carlos Ericksson Richter wrote:
> > > what means numbers 0, 2 and 10 in
> > >
> > > [jdbc/myConnection] Pool jdbc/myConnection [0/2/10] returned object
> > > org.jboss.pool.jdbc.xa.wrapper.XAConnectionImpl@7ec028 to the pool.
> > >
> > > log message?
> >
> > In the pool, there are 0 free connections, 2 are created (and, noticing
> the
> > 0, in use), and the max capacity is 10.
> > david jencks
> > >
> > >
> > > Thanks,
> > >
> > >
> > > Edson Richter
> > >
>
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user