![]() |
VOOZH | about |
Spring JDBC is used to build the Data Access Layer of enterprise applications, it enables developers to connect to the database and write SQL queries and update data to the relational database. The code related to the database has to be placed in DAO classes. SpringJDBC provides a class called JdbcTemplate to handle the database-related logic. JdbcTemplate is an abstraction layer on top of JDBC technology. The JdbcTemplate internally uses the Jdbc code but provides an API, so developers don’t have to write the Boiler Plate code.
Spring boot JDBC is similar to spring JDBC in terms of features, rather spring boot JDBC is different in implementation. As Spring boot follows convention over configuration it is simpler to implement JDBC in spring boot.in order
JDBC Using Spring Boot | JDBC Using Spring |
|---|---|
| Only one spring-boot-starter-jdbc dependency is required to make available all the Spring modules we need to perform JDBC operations. | Multiple dependencies like spring context and spring JDBC must be included in order to perform JDBC operations. |
| In spring boot we do not have to explicitly register template beans PlatformTransactionManager, JdbcTemplate, NamedParameterJdbcTemplate spring boot will create it for you automatically if not created. | The template beans PlatformTransactionManager, JdbcTemplate, NamedParameterJdbcTemplate must be registered in order to use JDBC in your application. |
| It auto-initializes data source bean if not mentioned explicitly and you can set the spring.datasource.initialize to false if you don't want to use the bean. | In spring JDBC, it is required to create a database bean either using XML or javaconfig. |
| Any database initialization script like deleting or creating a table in the .sql file gets executed automatically in spring boot JDBC. | Any database script in the .sql files needs to be given in the configuration file for it to work in spring JDBC. |