Posts

Spring JdbcClient Example

Image
In this section, we're gonna build a Spring Boot application that use Spring  JdbcClient to interact with PostgreSQL database. Spring Framework 6.1 introduced the JdbcClient API. As we all know, Spring Framework 6.1 is part of Spring Boot version 3.2.  We can use the Spring JdbcClient interface to define the query, set the parameters, and perform the DB operation, using a fluent API.  Fluent APIs are designed to make the code more readable and therefore easier to use. Wiring objects together using method chaining helps accomplish these readability and usability goals. An example for retrieving a Student as a Optional: public Optional < Student > findStudentById ( Long id) { String sql = "select id, name, age, gender, " + "email from students where id = :id" ; return jdbcClient .sql( sql ) .param( "id" , id) .query( Student . class ) .optional(); } What we will build? We will build a s

Spring Boot JdbcClient CRUD Example

Image
In this section, we're gonna build CRUD REST APIs using Spring Boot application that use Spring  JdbcClient  to interact with PostgreSQL database. We are recommending you to cover  Spring JdbcClient Example   tutorial to get better understanding about JdbcClient .  What we will build? We will build CRUD RESTFul APIs for a Simple Student Management System using Spring Boot, JDBC API, and the PostgreSQL database. In this application we use JdbcClient to interact with PostgreSQL database. Creating a spring boot application First, open the Spring initializr  https://start.spring.io Then, Provide the Group and Artifact name. We have provided Group name com.knf.dev.demo and Artifact spring-boot-jdbcclient-crud. Here I selected the Maven project - language Java 17 - Spring Boot 3.2.0, Spring Web,JDBC API, and PostgreSQL Driver. Then, click on the Generate button. When we click on the Generate button, it starts packing the project in a .zip(spring-boot-jdbcclient-crud) file and downloads t