DEV Community

loading...

How to use Spring JDBC Template with Spring Boot for Postgres DataBase

loizenai profile image loizenai ・2 min read

https://grokonez.com/spring-framework/spring-boot/how-to-use-jdbc-template-with-spring-boot-for-postgres-database

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

jdbc-postgresql

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 jdbc-postgresql-startproj

In SQL, select JDBC & PostgreSQL
jdbc-postgresql-pom-config

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:

https://grokonez.com/spring-framework/spring-boot/how-to-use-jdbc-template-with-spring-boot-for-postgres-database

How to use Spring JDBC Template with Spring Boot for Postgres DataBase

Discussion (0)

Forem Open with the Forem app