2

Call Stored Procedure using Spring Data and @Procedure

This post demonstrates how to call Stored Procedure using Spring Data and @Procedure.

Requirements

Stuff used in this post.

  • IntelliJ IDEA Ultimate 2016.3
  • Java 8
  • Windows 10 64bit
  • Spring Boot 1.5.6.RELEASE
  • Spring Initialzr
  • MySQL and MySQL Workbench

Spring Initialzr in IntelliJ IDEA

Database Table

First, we need to create a database table.

Create Stored Procedure

Entity and Repository

Then, we create our entity and repository.

Person entity

PersonRepository

Note the method name here. It is the same as our Stored Procedure. @Procedure maps this method to that actual stored procedure.

application.properties

Before we can access our database, we need a valid user account and the following properties set up in application.properties file.

Testing

The following codes are from our main Spring Boot class.

Output

Download the codes

https://github.com/Turreta/Call-Stored-Procedure-using-Spring-Data-and-Procedure