Q1. Explain Spring JDBC packages.
To handle different aspects of JDBC, Spring JDBC is divided into packages, as shown in following table:
Q2. What is JdbcTemplate
?
The JdbcTemplate
class instances are thread-safe once configured. A single JdbcTemplate
can be configured and injected in multiple DAOs. We can use JdbcTemplate
to execute different types of SQL statements. Data Manipulation Language (DML) is used to insert, retrieve, update, and delete data in database. The SELECT
, INSERT
, or UPDATE
statements are examples of DML. Data Definition Language (DDL) is used to either create or modify the structure of database objects in database. The CREATE
, ALTER
, and DROP
statements are examples of DDL.
Q3. Explain the JDBC operation in Spring.
The single executable unit for performing multiple operations is known as a batch. The batch update operation allows submitting multiple of SQL queries DataSource
for processing at once. Submitting multiple SQL queries together, instead of individually improves the performance. The JdbcTemplate
includes a support for executing the batch of statements through a JDBC Statement and PreparedStatement. The JdbcTemplate
includes two overloaded batchUpdate()
methods in support of this feature:
public int[] batchUpdate(String[] sql) throws DataAccessException
PreparedStatement
such as:public int[] batchUpdate(String sql, BatchPreparedStatementSetter bPSS) throws DataAccessException