ResultSet next() returning true when no rows

From: Seth Rubin <srubin(at)thoughtprocess(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: ResultSet next() returning true when no rows
Date: 2003-10-06 04:04:56
Message-ID: CNELLBDHOKALJPHOOBBEKEGHDOAA.srubin@thoughtprocess.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2003-10-06 04:47:00 Re: ResultSet next() returning true when no rows
Previous Message Andreas Prohaska 2003-10-05 12:20:33 Re: j2sdk1.4.2_01 vs. CLASSPATH problem?