pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Daniel Schaedler <postgres-jdbc@daniel.schaedler.name>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: problem to get nextval of a sequence
Date: Tue, 28 Dec 2004 08:08:27 -0500
Message-ID: <41D15ACB.8050109@fastcrypt.com> (raw)
In-Reply-To: <41D15580.3050700@daniel.schaedler.name>
References: <41D15580.3050700@daniel.schaedler.name>

Daniel,

You have to call ress.next() before you get the value.

Dave

Daniel Schaedler wrote:

> Hi List
>
> I try to get the 'nextval' of a sequence:
> ***
>   String query = "SELECT nextval('nodes_nodeid_seq')";
>   pstmt = conn.prepareStatement(query);
>   logger.debug("statement: " + pstmt.toString());
>   ResultSet ress = pstmt.executeQuery();
>   long newID = ress.getLong("nextval");  // <-- Exception
> ***
>
> I get the following Exception:
> ***
> org.postgresql.util.PSQLException: ResultSet not positioned properly, 
> perhaps you need to call next.
>     at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkResultSet(AbstractJdbc2ResultSet.java:2380) 
>
>     at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1821) 
>
>     at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getFixedString(AbstractJdbc2ResultSet.java:2326) 
>
>     at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:1935) 
>
>     at 
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2158) 
>
>     at org.daniel.pws.store.PostgresStore.newNode(PostgresStore.java:307)
>     at org.daniel.pws.store.StoreTester.main(StoreTester.java:71)
> 2004-12-28 13:41:57,983 - not able to get the new nodeID
> ****
>
> executing the query in PostgresSQL directly works, I get the correct 
> return value.
> The Query itself seems to be executet, as I get other exceptions if I 
> misspell the columnname (e.g.).
> I'm working with Postgres-jdbc: pg80b1-1.308.jdbc3.jar and JDK 1.5.0
>
> someone an Idea?
>
> wishing all a Happy new Year
> Daniel


-- 
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561




view thread (6+ messages)  latest in thread

Message-ID: <41D15ACB.8050109@fastcrypt.com>
Permalink:  ../41D15ACB.8050109@fastcrypt.com/
Also on:    postgresql.org/message-id/41D15ACB.8050109@fastcrypt.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, postgres-jdbc@daniel.schaedler.name
  Subject: Re: problem to get nextval of a sequence
  In-Reply-To: <41D15ACB.8050109@fastcrypt.com>
  References: <41D15580.3050700@daniel.schaedler.name> <41D15ACB.8050109@fastcrypt.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