Better Programming

Advice for programmers.

Follow publication

Member-only story

Building a Spring Boot REST API — Part 3: Integrating MySQL Database and JPA

Salisu Wada
Better Programming
Published in
6 min readDec 17, 2017

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.

Table Structure

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
);

Application Configuration

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Salisu Wada
Salisu Wada

Written by Salisu Wada

A busy researcher. Squeezing the little time I have to write #code

Write a response