skip to main content
Supported features : Auto-generated keys
 

Try DataDirect Cloud Now

Auto-generated keys

The driver supports retrieving the values of auto-generated keys. An auto-generated key returned by the driver is the value of an auto-increment column.
An application can return values of auto-generated keys when it executes an Insert statement. How you obtain these values depends on whether you are using an Insert statement that contains parameters.
*When using an Insert statement that contains no parameters, the driver supports the following forms of the Statement.execute and Statement.executeUpdate methods to inform the driver to return the values of auto-generated keys:
*Statement.execute(String sql, int autoGeneratedKeys) 
*Statement.execute(String sql, int[] columnIndexes) 
*Statement.execute(String sql, String[] columnNames) 
*Statement.executeUpdate(String sql, int autoGeneratedKeys) 
*Statement.executeUpdate(String sql, int[] columnIndexes) 
*Statement.executeUpdate(String sql, String[] columnNames) 
*When inserting data using a prepared statement, the driver supports the following forms of the Connection.prepareStatement method to inform the driver to return the values of auto-generated keys:
*Connection.prepareStatement(String sql,    int autoGeneratedKeys) 
*Connection.prepareStatement(String sql, int[] columnIndexes) 
*Connection.prepareStatement(String sql,    String[] columnNames) 
An application can retrieve values of auto-generated keys using the Statement.getGeneratedKeys() method. This method returns a ResultSet object with a column for each auto-generated key.