Member-only story
Building a Spring Boot REST API — Part 3: Integrating MySQL Database and JPA
Final part: MySQL database integration and Java Persistence API to query the database

In the previous tutorial, we’ve seen how we can send a request and get a response from the controller using hard-coded mocked data.
In this section, the MySQL database will be integrated and the Java Persistence API (JPA) to query the database. Think of the JPA as an object-relational mapping (ORM) library, similar to Eloquent, Doctrine, Entity Framework, etc.
Setting Up the MySQL Database
To get started, we need to have MySQL installed and a table created.

Open the MySQL terminal and run the following commands to create the database and the blogs table:
CREATE DATABASE restapi;USE restapi;CREATE TABLE blog (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(500) NOT NULL,
content VARCHAR(5000) NOT NULL
);