Retrieval of auto-generated 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 auto-generated or auto-incremented 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 will contain 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() will return the value of the last generated key only.

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