Skip site navigation (1) Skip section navigation (2)

Re: NullPointerException on call to next()

From: "Martin Dillard" <martin(at)edusoftinc(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: NullPointerException on call to next()
Date: 2001-11-16 00:50:46
Message-ID: 00ae01c16e38$ba25ade0$0301a8c0@market (view raw or flat)
Thread:
Lists: pgsql-jdbc
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I can solve this problem by replacing the current JDBC driver with
the 7.0 driver. What changed between the two versions and is anything
affected by using the outdated driver?
- ----- Original Message ----- 
From: Martin Dillard 
To: pgsql-jdbc(at)postgresql(dot)org 
Sent: Thursday, November 15, 2001 12:44 PM
Subject: NullPointerException on call to next()


- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A NullPointerException is being thrown from a call to next() in this
(simplified) code snippet:

            String sql = "SELECT * FROM my_table";
            stmt = pConn.createStatement();
            
            result = stmt.executeQuery(sql);
            
            while (result.next())
            {
                myObject = populateFromResult(result, true, pConn);
                
                myArrayList.add(myObject);
            }

The exception is thrown in the second iteration of the while loop
from result.next(). The method populateFromResult only calls getXXX()
methods on the ResultSet and creates another Statement on the
Connection and uses it to populate other fields in the object. The
Connection and the ResultSet are not closed. The new Statement on the
Connection IS CLOSED (could this be the problem???).

After decompiling the jdbc drivers, the offending line of code inside
ResultSet is:

if (++current_row >= rows.size())

I am using the JDBC drivers compiled from the 7.1.3 release of
Postgres running on Tomcat in Linux. The same code works fine on the
drivers from the 7.1RC2 release running on Resin in Windows.

The only previous posts I have found describing this problem
concluded that the problem was caused by closing the Statement or
executing a new query on it before the subsequent call to next(). I
have examined my code closely and am not using the ResultSet or
Statement for anything other than what you see in the code above.

Has anyone run across this problem? Does anyone have any suggestions?
______________________
Martin Dillard
Edusoft
martin(at)edusoftinc(dot)com

http://www.edusoftinc.com

- -----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use
<http://www.pgp.com>

iQA/AwUBO/QpKBiVliUcvJG9EQKxGQCePh9oLVFJ4dde8EcYzrBbt2kHdJIAn3oA
gaP82uKhG/iWOUpXnv7+9yXm
=YWFG
- -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>

iQA/AwUBO/Ri5RiVliUcvJG9EQK+sgCbBoR9QiQsF212tJyc1Dpi43NWzjUAmwT5
vqyK/Kg2sGFb1WEOp0wqVrfa
=eTl4
-----END PGP SIGNATURE-----

In response to

Responses

pgsql-jdbc by date

Next:From: Dave CramerDate: 2001-11-16 01:08:26
Subject: Re: NullPointerException on call to next()
Previous:From: Martin DillardDate: 2001-11-15 20:44:25
Subject: NullPointerException on call to next()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group