Nice!!!!!  did not know that

            s.execute("INSERT INTO " + testTable1 + " (NAME) VALUES('xyz')");
            int keyVal = Statement.RETURN_GENERATED_KEYS;
            System.out.println("KEYVAL = "+keyVal);

works perfect.

B-)

On Feb 12, 2008 3:57 PM, Peter Yuill <pyuill@objectix.com.au> wrote:
Oops,

try statement.executeUpdate("some query",
Statement.RETURN_GENERATED_KEYS)


----- Original message -----
From: "Peter Yuill" <pyuill@objectix.com.au>
To: "Derby Discussion" <derby-user@db.apache.org>,
derby-user@db.apache.org
Date: Wed, 13 Feb 2008 08:52:28 +1100
Subject: Re: Get auto increment value

The standard way to do it is to use the alternate execute eg
statement.executeUpdate("some query", true);
and then
statement.getGeneratedKeys()

Cheers,
Peter
----- Original message -----
From: "larsk" <larsk8@yahoo.se>
To: derby-user@db.apache.org
Date: Tue, 12 Feb 2008 13:41:47 -0800 (PST)
Subject: Get auto increment value


I am making a java-application that uses an apache derby database. One
of the
fields in one of the tables has auto increment applied (GENERATED BY
DEFAULT
AS IDENTITY). Is it possible to get the value that this field is going
to
get or what value it got when making an insert? Or do I have to make a
select to the database to know this?
I use the following code to insert data to the database:

--------------------

Connection con = DriverManager.getConnection(connectionString);

Statement state = con.createStatement();

try
{
       state.executeUpdate(queryString);
}

catch (Exception ex)
{
       throw(ex);
}

con.close();

--------------------

If anyone has any idea on how to make this know I would appreciate any
help.
--
View this message in context:
http://www.nabble.com/Get-auto-increment-value-tp15443701p15443701.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.