Обсуждение: ResultSet next() returning true when no rows

Поиск
Список
Период
Сортировка

ResultSet next() returning true when no rows

От
Seth Rubin
Дата:
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


Re: ResultSet next() returning true when no rows

От
Oliver Jowett
Дата:
On Mon, Oct 06, 2003 at 12:04:56AM -0400, Seth Rubin wrote:

> line 1548      while (rs.next());

You have a stray semicolon there.

-O

Re: ResultSet next() returning true when no rows

От
Seth Rubin
Дата:
I am so embarassed.  Thank you.

-----Original Message-----
From: Oliver Jowett [mailto:oliver@opencloud.com]
Sent: Monday, October 06, 2003 12:47 AM
To: Seth Rubin
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] ResultSet next() returning true when no rows


On Mon, Oct 06, 2003 at 12:04:56AM -0400, Seth Rubin wrote:

> line 1548      while (rs.next());

You have a stray semicolon there.

-O