Category: Database, github

by Consider the following Author entity that delegates the keys generation to the database system: Now, let's see how to retrieve the database auto-generated primary keys via getId(), JdbcTemplate and SimpleJdbcInsert. In JPA style, retrieving the auto-generated keys can be done via getId() as in the following example: Using JdbcTemplate to retrieve the auto-generated keys can be done via the update() method.

The KeyHolder object contains the auto-generated key returned by the update() method. In code lines: In the above example, the PreparedStatement is instructed to return the auto-generated keys via Statement.RETURN_GENERATED_KEYS.

Related Articles