RE: getting nextval from query?

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: "'G(dot)L(dot) Grobe'" <gary(at)grobe(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: RE: getting nextval from query?
Date: 2001-07-29 12:02:23
Message-ID: 02bd01c11826$545cdb40$8201a8c0@inspiron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of G.L. Grobe
Sent: July 29, 2001 1:56 AM
To: pgsql-general(at)postgresql(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2001-07-29 12:26:32 [Fwd: MySQL Benchmark page - Problem with vacuum() in PostgreSQL]
Previous Message G.L. Grobe 2001-07-29 05:56:18 getting nextval from query?