You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "KNOX, Liam, FM" <Li...@rbos.com> on 2003/08/18 16:15:56 UTC

dbcp bug

Hi

I've been trying to use commons-dbcp within in our existing infrastructure
and have come across a problem.
The code below simply excutes a stored proc on Sybase which returns no
values. This causes a NullPointerException due the DelegatingResultSet.close
calling close on the null underlying ResultSet when the statement is closed.

Its quite interesting that commenting out the bold line actually stops the
exception occuring !!

Is this a bug ??

Cheers

Liam

// code

public class DataSourceTest {

    public static void main(String[] args) throws Exception {

        System.out.println("Loading underlying JDBC driver.");
        Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
        ObjectPool connectionPool = new GenericObjectPool(null,10);
        ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory("jdbc:sybase:Tds:lon0658xus.fm.rbsgrp.net:205
0/finesse_test1","finessedbo","finessedbo");
        PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,t
rue);
        DataSource dataSource = new PoolingDataSource(connectionPool);

        System.out.println("Done.");

        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;

        try {
            System.out.println("Creating connection.");
            conn = dataSource.getConnection();
            System.out.println("Creating callable statement.");
            stmt = conn.prepareCall("TruncateDb");
            System.out.println("Executing callable statement.");
            stmt.execute();
            rs = stmt.getResultSet();

        } catch(SQLException e) {
            e.printStackTrace();
        } finally {

            try {
              System.out.println("Closing Statement.");
            stmt.close(); } catch(Exception e) { e.printStackTrace();}
            try {
              conn.commit();
              conn.close();
          } catch(Exception e) { e.printStackTrace();}
        }
    }

}
   

// output


Loading underlying JDBC driver.
Done.
Creating connection.
Creating callable statement.
Executing callable statement.
Closing Statement.
java.lang.NullPointerException
	at
org.apache.commons.dbcp.DelegatingResultSet.close(DelegatingResultSet.java:1
32)
	at
org.apache.commons.dbcp.DelegatingCallableStatement.close(DelegatingCallable
Statement.java:140)
	at dbcp.DataSourceTest.main(DataSourceTest.java:48)






***********************************************************************************
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
The Royal Bank of Scotland plc is registered in Scotland No 90312
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
             Regulated by the Financial Services Authority

            Visit our website at http://www.rbs.co.uk/CBFM/
***********************************************************************************


RE: dbcp bug

Posted by "Noel J. Bergman" <no...@devtech.com>.
Check this against the CVS.  There were recent changes to make sure that
operations were not performed on null references.

	--- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: dbcp bug

Posted by "Noel J. Bergman" <no...@devtech.com>.
Check this against the CVS.  There were recent changes to make sure that
operations were not performed on null references.

	--- Noel