Connecting your Spring Boot Application to PostgreSQL

Mercy Jemosop
2 min readSep 28, 2021

Introduction

For this walk through you need to have PostgreSQL installed in your machine before getting started.

Step 1: Install PostgreSQL

I used this blog to install postgresql you can search for whatever resource will work for you. You can also try this.

If you done with the setup, create a database for your project. You can do it from commandline or if you have installed pgAdmin open and create the database from there.

Finally click save.

Step 2: To your pom.xml add PostgreSQL dependency

Step 3: Create a simple entity class to test if our configuration is working

Step 4: Add PostgreSQL configuration on your application.property

# specify the port your spring boot application will run on
server.port:8081

# data source is a factory for connecting to any physical data source.
spring.datasource.url=jdbc:postgresql://localhost:5432/tables_management

# postgres configurations, you postgresql password and username
#the username and password is the one you set during installation
spring.datasource.username=mercy #your postgresql username
spring.datasource.password=mercy # your postgresql password
# create table if it doesn't exist
spring.jpa.hibernate.ddl-auto = create

Step 3: Run your spring-boot Application

To check if it’s connecting:

Check your console if your table is created

or open you pgAdmin, your database, schemas, public, tables and check if your table was created.

Hope this works for you.

Happy coding!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

--

--

Mercy Jemosop

Software Developer. I am open to job referrals. connect with me on twitter @kipyegon_mercy