|
Home > Archive > PostgreSQL JDBC > April 2005 > isLast() and empty ResultSet
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
isLast() and empty ResultSet
|
|
| Ruediger Herrmann 2005-04-21, 8:24 pm |
| Hello,
I implemented an Iterator interface iterating over a ResultSet. Therefore
I rely on isLast() to implement the Iterator#hasNext() method. This works
fine unless the whole ResultSet is empty.
For empty RresultSets, isLast always returns true.
Stepping through the code I found the reason therefore. Line 544 of
AbstractJdbc2ResultS
et says
if (rows_size == 0)
return false; // No rows.
At least to me this is suspicious as I would return the opposite. Might that
be a bug or is there any other reason to behave like this?
I am using JDBC Driver 8.0 Build 311 and Server Version 8.0.2.
Regards
Rüdiger
--
+++ NEU: GMX DSL_Flatrate! Schon ab 14,99 EUR/Monat! +++
GMX Garantie: Surfen ohne Tempo-Limit! http://www.gmx.net/de/go/dsl
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere
" to majordomo@postgresql
.org)
| |
| Ruediger Herrmann 2005-04-22, 7:23 am |
|
Thanks a lot to all of you for the replies.
I'm now using isBeforeFirst() to test for an empty
ResultSet, wich as far as my tests show seems to work
if it is the first thing done.
Regards
Rüdiger
--- Oliver Jowett <oliver@opencloud.com> wrote:
> Ruediger Herrmann wrote:
> a ResultSet. Therefore
> Iterator#hasNext() method. This works
> therefore. Line 544 of
> return the opposite. Might that
> like this?
>
> It's not a bug, AFAIK. isLast() returns true if the
> resultset is
> positioned *on* the last row of the resultset. This
> means that if you
> have a 5-row resultset, isLast() is true when the
> 5th row is the
> currently active row (and you can retrieve data from
> that row at that
> point).
>
> For a 0-row resultset, we can never be on the last
> row as there are no
> rows at all.
>
> You could try something like this for your hasNext()
> condition:
>
> rs.isBeforeFirst() || (rs.getRow() != 0 &&
> !rs.isLast())
>
> (note that isBeforeFirst() returns false on an empty
> resultset, per javadoc)
>
> -O
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo@postgresql
.org
>
>
>
--
+++ GMX - Die erste Adresse für Mail, Message, More +++
1 GB Mailbox bereits in GMX FreeMail http://www.gmx.net/de/go/mail
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly
|
|
|
|
|