Skip site navigation (1) Skip section navigation (2)

Re: problem to get nextval of a sequence

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Daniel Schaedler <postgres-jdbc(at)daniel(dot)schaedler(dot)name>
Cc: Guillaume Cottenceau <gc(at)mnc(dot)ch>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: problem to get nextval of a sequence
Date: 2004-12-28 14:05:36
Message-ID: 41D16830.7000800@fastcrypt.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Daniel,

The spec says that you must call next to position the cursor. What 
happens if nothing comes back? ie an empty result set ?

Dave

Daniel Schaedler wrote:

> Guillaume Cottenceau wrote:
>
>> Daniel Schaedler <postgres-jdbc 'at' daniel.schaedler.name> writes:
>>
>>
>>> 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.
>>
>>
>>
>> "perhaps you need to call next".
>>
>> Have you tried calling next?
>
>
> uhhh....
> ....now yes...and it works.
>
> When I expect only one set of data, I never call next. That's why I 
> ignored the statement.
>
> thanks anyway.
> Daniel
>
>
>

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


In response to

Responses

pgsql-jdbc by date

Next:From: Dave CramerDate: 2004-12-28 14:23:26
Subject: Re: Open connections
Previous:From: NicoDate: 2004-12-28 13:33:08
Subject: Re: Open connections

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group