ResultSet next() returning true when no rows - Mailing list pgsql-jdbc

From Seth Rubin
Subject ResultSet next() returning true when no rows
Date
Msg-id CNELLBDHOKALJPHOOBBEKEGHDOAA.srubin@thoughtprocess.com
Whole thread Raw
Responses Re: ResultSet next() returning true when no rows
List pgsql-jdbc
I'm using the latest pg73jdbc3.jar production file (from this past August)
with JDK 1.4.2_01 with Tomcat 4.1.27.  On this code:

line 1547      rs = st.executeQuery(sqlStatement);
line 1548      while (rs.next());
line 1549      {
line 1550        int res_id = rs.getInt(1);

The rs.getInt is blowing up with the following error:

Result set not positioned properly, perhaps you need to call next().
    at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.checkResultSet(AbstractJdbc1Resu
ltSet.java:673)
    at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getString(AbstractJdbc1ResultSet
.java:91)
    at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getFixedString(AbstractJdbc1Resu
ltSet.java:642)
    at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.ja
va:144)
    at com.thoughtprocess.SchedServer.schedQuery(SchedServer.java:1550)

I run the same SQL statement at the psql prompt, and I get zero rows
returned, so for some reason rs.next is returning true even though there's
no data.

What's more maddening is that I try the same code in a separate standalone
java app, and it doesn't experience the same problem.

So there's something funky in my servlet, but I can't figure out what it is.
I've even tried creating a new connection from scratch right before this
SQL, but no dice.  The only thing I can think of is that another thread is
running the exact same query at almost the same second, but I'd hate to
think it's that vulnerable.

Any insights appreciated...
Also, is there a place where the JDBC3 source is available for perusal?

-- Seth


pgsql-jdbc by date:

Previous
From: Andreas Prohaska
Date:
Subject: Re: j2sdk1.4.2_01 vs. CLASSPATH problem?
Next
From: Oliver Jowett
Date:
Subject: Re: ResultSet next() returning true when no rows