Define Multiple DataSources in Spring Boot

Introduction This tutorial will show you how you can define multiple datasources in Spring Boot application. I had shown how to define multiple datasources in Spring application, but here I will define multiple datasources in Spring Boot application. There may be situations where you need to define multiple datasources in Spring Boot application. For instance, you may need to define…

Spring MVC and JDBC CRUD with zero XML

In my other tutorials Spring MVC CRUD example with JDBC Spring MVC and Spring JDBC Example ,  Spring MVC and JDBC CRUD Example  I have used XML configurations but in this tutorial I have used only Annotation, so it means it uses zero XML configurations. This example shows how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also…

Spring MVC and JDBC CRUD Example

Introduction This tutorial Spring MVC and JDBC CRUD example shows how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also find how JDBC works with Spring MVC. We will also see how annotation like @Autowired works in Spring MVC and JDBC CRUD example. You will also see how datasource is configured in Spring. In this example…

Spring NamedParameterJdbcTemplate And Collections.singletonMap Example

NamedParameterJdbcTemplate and Collections.singletonMap In this post I will show you how to use NamedParameterJdbcTemplate and Collections.singletonMap to execute query for returning result. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (?) arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTemplate to do…

Spring NamedParameterJdbcTemplate And BeanPropertySqlParameterSource Example

BeanPropertySqlParameterSource In this post I will show you how to use NamedParameterJdbcTemplate and BeanPropertySqlParameterSource to execute query. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (?) arguments. The NamedParameterJdbcTemplate class wraps a JdbcTemplate, and delegates to the wrapped JdbcTemplate to do much of its work. An…

Spring NamedParameterJdbcTemplate and MapSqlParameterSource Example

Introduction In this post I will show you how to use NamedParameterJdbcTemplate and MapSqlParameterSource to execute query for inserting or retrieving results from database table. The NamedParameterJdbcTemplate class adds support for programming JDBC statements using named parameters, as opposed to programming JDBC statements using only classic placeholder (?) arguments. An SqlParameterSource is a source of named parameter values to a…

Get Auto-generated Id in Spring JDBC using SimpleJdbcInsert

Auro-generated Id In this post I will show you how to get auto generated id of a newly inserted row in table. Spring provides an easy way to get this auto-generated key using executeAndReturnKey() method of SimpleJdbcInsert which is supported Spring JDBC 3 onwards. For most of the records I will use auto generated Id value on database side to…

Auto-generated Id In Spring JDBC Using PreparedStatement

Generated Id In this post I will show you how to get auto generated id of a newly inserted row in table. Spring provides an easy way to get this auto-generated key using KeyHolder which is supported Spring JDBC 3 onward. I am going to use PreparedStatement to get the auto generated id value. For most of the records, I…

Spring @PostConstruct and @PreDestroy Example

In this tutorial I will show you how we can use @PostConstruct and @PreDestroy annotation in Spring framework. @PostConstruct and @PreDestroy annotations are generally considered best practices for receiving life cycle callbacks in a modern Spring application. Using these annotations means that our beans are not coupled to Spring specific interfaces. Sometimes we need to load some data or perform…

Select Single and Multiple Records using Spring JdbcTemplate

Record Selection Using Spring JdbcTemplate This tutorial will show you how you can select or fetch data from a database using Spring JdbcTemplate. I am going to use Spring Boot framework to select single record, multiple records and only single field or column value from the database. simplifies the use of JDBC and helps to avoid common errors. It executes…