
Once the statement has been executed, the KeyHolder contains the ID of the newly inserted record. Our POJO class Employee, which will accompany us through the example, looks like this: class Employee ), it is essential that we pass a string array containing the names or indexes of all key columns as the last parameter.Īs a second parameter, the update() method expects the mentioned KeyHolder. If you still want to try the example with MySQL, please have a look at blog post Configuring Spring Boot for MySQL or you can use a docker container. Thanks to the autoconfiguration functionality of Spring Boot, the H2 database is available to us immediately after the application starts. This eliminates the need to set up a MySQL server and configuration of the connection. To keep the demo project as simple and uncomplicated as possible, we use the In-Memory SQL database H2. This dependency contains the class JdbcTemplate and also allows us to connect to an embedded database. The Dependency spring-boot-starter-jdbc is a starter for using JDBC in Spring Boot. opening and closing of connections, is taken from usīefore we really get started, I would like to take a closer look at the following points of the project setup:įor the JdbcTemplate demo project we need the following two dependencies in our Spring Boot based application:
#SELECT FOR UPDATE SPRING JDBCTEMPLATE HOW TO#


The JDBC API has the following downsides: Spring Support for JDBC focuses on the JdbcTemplate class, which is internally based on the JDBC API of the Java SDK.Īnyone who has ever worked with the JDBC API knows that using it creates a lot of boilerplate code, making it difficult to read and maintain. If we want to perform CRUD operations on a relational database the Spring ecosystem provides Spring Data JPA and Spring Support for JDBC.
