Re: problem to get nextval of a sequence - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: problem to get nextval of a sequence
Date
Msg-id 41D16830.7000800@fastcrypt.com
Whole thread Raw
In response to Re: problem to get nextval of a sequence  (Daniel Schaedler <postgres-jdbc@daniel.schaedler.name>)
Responses Re: problem to get nextval of a sequence  (Guillaume Cottenceau <gc@mnc.ch>)
List 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


pgsql-jdbc by date:

Previous
From: "Nico"
Date:
Subject: Re: Open connections
Next
From: Dave Cramer
Date:
Subject: Re: Open connections