Connecting Spring Boot and PostgreSQL database – Part 1

In todays tutorial, we will be setting up a postgreSQL database with a Java Spring Boot rest service.

Before we begin with the Java service, we will need to install PostgreSQL. You can find their latest downloads on their website. When you have downloaded and installed this on your machine, we will then set up the database and table.

First, check your PostgreSQL installation and that it is properly added onto your path. You can test this by opening up a command:

$ psql --version

This should return the version of PostgreSQL installed.

Depending on how you have installed PostgreSQL, you will have a default username and password of postgres.

Log into Postgres to check this, type:

$ psql postgres

postgres=# \du

this will list the current users that are installed. For more information about this, check out this link.

Presuming that is all installed, I will use the username and password Postgres for this tutorial and this will be a default user on the Postgres app for mac.

Log into Postgres with:

$ psql postgres

then, run the following SQL script:

postgres=# CREATE TABLE users (
id char(5),
username varchar(40)
);

This will create a table for users with columns id and username.

In part 2, we will create the Java app that will insert and remove data from the database.