This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const posts = [ | |
{ | |
id: 1, | |
title: 'Spring JDBC returning auto-generated keys using PreparedStatementCreator and PreparedStatementCallback', | |
content: `In this post, we will look into how to retrieve auto-generated keys in JDBC. We will also explore usage of PreparedStatementCreator and PreparedStatementCallback in JdbcTemplate. | |
There are cases when you rely on Database server to auto generate values for some columns of the table. E.g. auto increment primary key, creation_date or any other column while inserting records. There is a way with which you can retrieve those auto-generated keys when you execute the insert statement. Let's see how you can do this using Spring JDBC but first we will see what PreparedStatementCreator and PreparedStatementCallback interfaces are. | |
What is PreparedStatementCreator? | |
There are cases when you want to create PreparedStatement yourself. One use case is to return auto generated keys. In that case, Spring JDBC provides you an option to do so by provi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/api/employees") | |
public class EmployeeController { | |
@RequestMapping | |
public ResponseEntity<List<Employee>> getAll() { | |
return ResponseEntity.ok(Collections.emptyList()); | |
} | |
@RequestMapping("/{employeeId}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run complete. Total time: 00:13:40 | |
Benchmark Mode Cnt Score Error Units | |
MyBenchmark.testAdd thrpt 200 7048.966 ± 188.886 ops/s | |
MyBenchmark.testComposed thrpt 200 7127.034 ± 178.861 ops/s |