X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A714D53E0D for ; Fri, 22 Apr 2005 05:45:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52934-10 for ; Fri, 22 Apr 2005 08:45:56 +0000 (GMT) Received: from mail.gmx.net (mail.gmx.de [213.165.64.20]) by svr1.postgresql.org (Postfix) with SMTP id 40D8153E00 for ; Fri, 22 Apr 2005 05:45:55 -0300 (ADT) Received: (qmail 17963 invoked by uid 0); 22 Apr 2005 08:45:56 -0000 Received: from 84.163.181.163 by www16.gmx.net with HTTP; Fri, 22 Apr 2005 10:45:56 +0200 (MEST) Date: Fri, 22 Apr 2005 10:45:56 +0200 (MEST) From: "Ruediger Herrmann" To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Subject: Re: isLast() and empty ResultSet X-Priority: 3 (Normal) X-Authenticated: #1351255 Message-ID: <14442.1114159556@www16.gmx.net> X-Mailer: WWW-Mail 1.6 (Global Message Exchange) X-Flags: 0001 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.025 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200504/129 X-Sequence-Number: 12736 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 wrote: > Ruediger Herrmann wrote: > > 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 > > AbstractJdbc2ResultSet 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? > > 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