Connecting to a database
We have already configured our PostgreSQL database and initialized our Spring Boot application with the needed dependencies. Now, we will learn how to connect our PostgreSQL to our application. There are two ways we can connect to our database – the first is through Spring JDBC, and the other is Spring Data JPA. Spring Data JPA is the most convenient way to connect to our database, but we will demonstrate both methods in this section.
Configuring the database properties
The first thing we need to do is configure the database properties in our Spring Boot application. We need to specify the server URL of the database, the admin username, and the password by adding the following source code to the application.properties
file:
spring.datasource.url=jdbc:postgresql://localhost:5432/springDB spring.datasource.username=postgres spring.datasource.password=password
In the preceding example, we can see that we have configured the basic connection...