top of page
Writer's pictureJosef Mayrhofer

Create a lightweight Java Spring Boot App to store Data in PostgresSQL Database

Updated: May 26, 2023

In this exercise, we use a Java Sprintboot and Web UI to read, create, read, and delete data from PostgresSQL. The idea would be same from last blog post, and we use the Postgresql instead MongoDB. The most part that we didn’t change, we only need to add a new dependency for Postgresql, and new controller class to connect to postgresql database.

The functionality of our sample app includes

  • Create, edit and delete contacts

  • If a user clicks the New Contact button a form is displayed

  • We can provide a Name and Email for our new contacts

  • We can save the contacts

Web UI to visualize contacts and create new Contacts


Web UI to add a contact name and email and Save it


We will reuse the code from our last Springboot example on the link below

Step 1: Download the Postgresql and install it, then set up password and port accordingly

Download the installer from the link PostgreSQL: Downloads Then install it by following the instruction


Step 2: Create CONTACT table in pgAdmin

open the pgAdmin, and enter the password that given at in installation process then create a table with sql query



Step 3: We add a few additional dependencies in the pom.xml



Step 4: We create a new controller class and add some new functions

first of all, we need to create few parameters for connecting postgresql database, and the connection which we will repeatedly use it.





then, we need the entire list of contact



add new contact into database



review the existing contact



delete the contact by name



Step 5: Keep a couple functions

there’re only two function that don’t need to change



Step 6: Rewrite rest functions

everything is the same idea, we just need to write it for the postgresql database

to get the list of the contact



to review the existing contact



to save a new contact



to delete the existing contact



Keep up the great work! Happy Performance Engineering!


#java #springboot #postgresql


35 views0 comments

Comments


bottom of page