Retrieval of autogenerated keys

Adds a way to retrieve values from columns that contain automatically generated values. JDBC 3.0 addresses the common need to obtain the value of an autogenerated or autoincremented key.

Determine the value of a generated key

To inform the driver that you want to retrieve the auto-generated keys, pass the constant Statement.RETURN_GENERATED_KEYS as the second parameter of the Statement.execute() method. After you have executed the statement, call Statement.getGeneratedKeys() to retrieve the generated keys. The result set contains a row for each generated key retrieved.

NoteAdaptive Server cannot return a result set of generated keys. If you execute a batch of insert commands, invoking Statement.getGeneratedKeys() returns only the value of the last generated key.

For more information about retrieving auto-generated keys, including a sample code, search for “retrieving automatically generated keys” on the Sun Microsystems Web site.