ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Jdbc Select And Get Generated Key
    카테고리 없음 2020. 11. 4. 15:22


    JDBC's auto-generated keys feature provides a way to retrieve valuesfrom columns that are part of an index or have a default value assigned. Derby supports the auto-incrementfeature, which allows users to create columns in tables for which the databasesystem automatically assigns increasing integer values. Users can call the method Statement.getGeneratedKeysto retrieve the value of such a column. This method returns a ResultSet objectwith a column for the automatically generated key. Calling ResultSet.getMetaData onthe ResultSet object returned by getGeneratedKeys produces a ResultSetMetaData objectthat is similar to that returned by IDENTITY_VAL_LOCAL.

    Retrieving auto-generated keys for an INSERT statement. With the IBM® Data Server Driver for JDBC and SQLJ, you can use JDBC 3.0 methods to retrieve the keys that are automatically generated when you execute an INSERT statement. To retrieve automatically generated keys that are generated by an INSERT statement, you need to perform these steps.

    Jdbc Select And Get Generated Key

    Users can indicate that auto-generated columns should be made availablefor retrieval by passing one of the following values as a second argumentto the Connection.prepareStatement, Statement.execute, or Statement.executeUpdate methods:

    • A constant indicating that auto-generated keys should be made available. The specific constant to use is Statement.RETURN_GENERATED_KEYS.
    • An array of the names of the columns in the inserted row that should be made available. If any column name in the array does not designatean auto-increment column, Derby will throw an error with the Derby embeddeddriver. With the client driver, the one element column name is ignored currently and the value returned corresponds to the identity column. To ensure compatibility with future changes an application should ensure the column described is the identity column. If the column name corresponds to another column or a non-existent column then future changes may result in a value for a different column being returned or an exception being thrown.
    • An array of the positions of the columns in the inserted row that shouldbe made available. If any column position in the array does not correlate to an auto-increment column, Derby willthrow an error with the Derby embeddeddriver. With the client driver, the one element position array is ignored currently and the value returned corresponds to the identity column. To ensure compatibility with future changes an application should ensure the column described is the identity column. If the position corresponds to another column or a non-existent column then future changes may result in a value for a different column being returned or an exception being thrown.

    Jdbc Select Query Example

    Example

    Assume that we have a table TABLE1 definedas follows:

    Generate public ssh key from private. The following three code fragments will all do the same thing:that is, they will create a ResultSet that contains the value of C12 that is inserted into TABLE1.

    Code fragment 1:

    Code fragment 2: https://diugagefau.tistory.com/7.

    Code fragment 3:

    Preparedstatement Return_generated_keys

    If there is no indication that auto-generated columns shouldbe made available for retrieval, a call to Statement.getGeneratedKeys will return a null ResultSet.





Designed by Tistory.