Select Records using queryForObject, queryForList, BeanPropertyRowMapper in Spring JdbcTemplate

Introduction In this post we will see how to select records using queryForObject, queryForList, BeanPropertyRowMapper in Spring JdbcTemplate. Here we will create annotation based example. If you need XML based application then you can refer to the example here. Spring’s queryForObject is used to fetch single row from the database. Spring’s queryForList and BeanPropertyRowMapper are used to fetch multiple rows from the database. Therefore we will fetch single and multiple rows from the database using Spring JdbcTemplate.

Continue

Batch Insertion using Spring JdbcTemplate

Introduction In this post we will see an example on batch insertion using Spring JdbcTemplate. We had seen the similar example using XML configuration previously but here we will create annotation based application. So we will see how we can insert a large data-set into a database at once using Spring JdbcTemplate. Sometimes we need to insert or update large number of records in the database. It’s not a good idea to insert multiple records into database one by one in a traditional approach. It will hit the application’s performance.…

Continue

Single and Multiple Record Insert using Spring JdbcTemplate

Introduction We will see example on single and multiple insert using Spring JdbcTemplate. We have seen similar example using XML based configuration but here we will see annotation based configuration to insert single or multiple records into database table. We will use here MySQL server 8.0.17 with Spring JdbcTemplate to insert data into database table. We can insert one or multiple records into database one by one in a traditional approach. Spring provides insert operation with the help of JdbcTemplate, it inserts or updates records into database in one shot.…

Continue

Select Single and Multiple Records 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 core JDBC workflow, leaving application code to provide SQL and extract results. This class executes SQL queries or updates, initiating iteration over ResultSets and catching JDBC exceptions and translating them to the generic, more informative…

Continue

Insert Single and Multiple Records Example using Spring JdbcTemplate

This tutorial will show you how you can insert an object or multiple objects into a database using Spring JdbcTemplate. So you are going to see how to insert single record and multiple records into database table. I am going to use PreparedStatement and BatchPreparedStatementSetter for inserting multiple records. Sometimes you need to insert or update one or few records in the database. You can insert one or multiple records into database one by one in a traditional approach. Spring provides insert operation with the help of JdbcTemplate, it inserts or…

Continue