pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jon Barnett <jbarnett@pobox.com>
To: 'Peter Mount' <petermount@it.maidstone.gov.uk>
To: 'pgsql-interfaces@hub.org' <pgsql-interfaces@hub.org>
Subject: RE: [INTERFACES] JDBC next() method
Date: Thu, 15 Apr 1999 00:37:03 +1000
Message-ID: <01BE86D8.15D52260.jbarnett@pobox.com> (raw)

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.



view thread (13+ messages)  latest in thread

Message-ID: <01BE86D8.15D52260.jbarnett@pobox.com>
Permalink:  ../01BE86D8.15D52260.jbarnett@pobox.com/
Also on:    postgresql.org/message-id/01BE86D8.15D52260.jbarnett@pobox.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: jbarnett@pobox.com, petermount@it.maidstone.gov.uk, pgsql-interfaces@hub.org
  Subject: RE: [INTERFACES] JDBC next() method
  In-Reply-To: <01BE86D8.15D52260.jbarnett@pobox.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox