JDBC 3.0 addresses the common need to obtain from columns the value of an autogenerated or autoincremented key.
To retrieve autogenerated 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 retrieved key.
For more information about retrieving autogenerated keys, including a sample code, search for “retrieving automatically generated keys” on the Oracle Java Web site.