getting nextval from query?

Started by G.L. Grobeover 24 years ago2 messagesgeneral
Jump to latest
#1G.L. Grobe
gary@grobe.net

To create a primary key for one of my session beans within the ejbCreate(), I'm doing a the following.

...
query = "SELECT NEXTVAL('versions_seq')";

pstmt = dbConn.prepareStatement(query);

rs = pstmt.executeQuery();

rs.next();
num = (int) rs.getInt("last_value");

But as show by the exception below, this does not work. How do I get the nextval value out from this query? So it's an attribute ... but I'd still like to know how to get to it.

[Default] Exception = The column name last_value not found.
[BuildKit] TRANSACTION ROLLBACK EXCEPTION:null; nested exception is:
javax.ejb.EJBException

Any help much appreciated.

#2Dave Cramer
pg@fastcrypt.com
In reply to: G.L. Grobe (#1)
RE: getting nextval from query?

Gary,

That is because the column name is actually nextval. you need to change
your code to

num = (int)rs.getInt("nextval);

Dave

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of G.L. Grobe
Sent: July 29, 2001 1:56 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] getting nextval from query?

To create a primary key for one of my session beans within the
ejbCreate(), I'm doing a the following.

...
query = "SELECT NEXTVAL('versions_seq')";

pstmt = dbConn.prepareStatement(query);

rs = pstmt.executeQuery();

rs.next();
num = (int) rs.getInt("last_value");

But as show by the exception below, this does not work. How do I get the
nextval value out from this query? So it's an attribute ... but I'd
still like to know how to get to it.

[Default] Exception = The column name last_value not found.
[BuildKit] TRANSACTION ROLLBACK EXCEPTION:null; nested exception is:
javax.ejb.EJBException

Any help much appreciated.