Received: from m4.c2.telstra-mm.net.au (m4.c2.telstra-mm.net.au [24.192.3.19]) by hub.org (8.9.2/8.9.1) with ESMTP id KAA10876 for ; Wed, 14 Apr 1999 10:39:09 -0400 (EDT) (envelope-from jbarnett@pobox.com) Received: from m5.c2.telstra-mm.net.au (m5.c2.telstra-mm.net.au [24.192.3.20]) by m4.c2.telstra-mm.net.au (8.8.6 (PHNE_14041)/8.8.6) with ESMTP id AAA17351; Thu, 15 Apr 1999 00:39:07 +1000 (EST) X-BPC-Relay-Envelope-From: jbarnett@pobox.com X-BPC-Relay-Sender-Host: m5.c2.telstra-mm.net.au [24.192.3.20] X-BPC-Relay-Info: Message delivered as CC or BCC. Received: from persephone.hsys.com.au (CPE-24-192-48-71.nsw.bigpond.net.au [24.192.48.71]) by m5.c2.telstra-mm.net.au (8.8.6 (PHNE_14041)/8.8.6) with SMTP id AAA07108; Thu, 15 Apr 1999 00:39:06 +1000 (EST) Received: by localhost with Microsoft MAPI; Thu, 15 Apr 1999 00:37:05 +1000 Message-ID: <01BE86D8.15D52260.jbarnett@pobox.com> From: Jon Barnett Reply-To: "jbarnett@pobox.com" To: "'Peter Mount'" , "'pgsql-interfaces@hub.org'" Subject: RE: [INTERFACES] JDBC next() method Date: Thu, 15 Apr 1999 00:37:03 +1000 X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wednesday, 14 April 1999 23:18, Peter Mount [SMTP:petermount@it.maidstone.gov.uk] wrote: > This looks ok. > > queryResult is null if there was an error in the query, so you should > check for that. > > However, normal use would have the result parsed within a > while(queryResult.next()) {} loop, so your interpretation is correct. I don't think the query should give an error - as the query is at least syntactically correct. Certainly, if I check for a queryResult == null, the condition doesn't occur for an empty table. I just had a quick browse on some old JDBC notes and it looks like the correct solution is: queryResult = dbStatement.executeQuery("select max(history_id) from history"); queryResult.next(); nextID = queryResult.getLong(1) + 1; if (queryResult.wasNull()) nextID = 0; Note: queryResult.wasNull() only works immediately after calling a getxxx method. Thanks. JonB.