RE: [INTERFACES] JDBC next() method

From: Jon Barnett <jbarnett(at)pobox(dot)com>
To: "'Peter Mount'" <petermount(at)it(dot)maidstone(dot)gov(dot)uk>, "'pgsql-interfaces(at)hub(dot)org'" <pgsql-interfaces(at)hub(dot)org>
Subject: RE: [INTERFACES] JDBC next() method
Date: 1999-04-14 14:37:03
Message-ID: 01BE86D8.15D52260.jbarnett@pobox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Wednesday, 14 April 1999 23:18, Peter Mount
[SMTP:petermount(at)it(dot)maidstone(dot)gov(dot)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.

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 1999-04-14 14:51:39 RE: [INTERFACES] JDBC next() method
Previous Message Peter Mount 1999-04-14 13:18:23 RE: [INTERFACES] JDBC next() method