db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Yuill" <pyu...@objectix.com.au>
Subject Re: Get auto increment value
Date Thu, 14 Feb 2008 00:55:02 GMT
I think my previous post might have been misleading. The code below is
only getting the int value of the RETURN_GENERATED_KEYS constant. 

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

The code needs to look like this:

s.execute("INSERT INTO " + testTable1 + " (NAME) VALUES('xyz')",
Statement.RETURN_GENERATED_KEYS);
ResultSet keys = s.getGeneratedKeys();
if (keys.next()) {
  System.out.println("KEYVAL = " + keys.getInt(1));
}

Mime
View raw message