How to use Spring JDBC Template with Spring Boot for Postgres DataBase
The tutorial shows you how to use Spring JDBC Template to access & manipulate database (Postgres DB) with Spring Boot.
I. Technology
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.4.0.RELEASE
II. Overview of Spring JDBC Template project
1. Design
Class mapping with design:
- Client: JdbctemplatePostgresApplication.java
- Bussiness Layer: CustomerService interface, and CustomerServiceImpl implement CustomerService.
- Dao Layer: CustomerDao interface and CustomerDaoImpl implement CustomerDao.
- Database: Postgres.
- Model: Customer class.
2. Step to do
- Create SpringBoot project
- Config DataSource
- Create postgresql-schema
- Create Model: Customer
- Build Dao layer: CustomerDao interface; CustomerImpl
- Build Business Layer: CustomerService interface & CustomerServiceImpl
- Build Client: JdbctemplatePostgresApplication
III. Practice
1. Create SpringBoot project
File->New->Spring Starter Project
In SQL, select JDBC & PostgreSQL
Press Finish.
2. Config DataSource
In application.properties file:
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=postgres
spring.datasource.password=123
3. Create Progresql Schema
Create schema-postgresql.sql file and places in src/main/resources folder with content
More at:
How to use Spring JDBC Template with Spring Boot for Postgres DataBase
Top comments (0)