Software Development

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

[wp_ad_camp_1]

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

[wp_ad_camp_2]

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.

[wp_ad_camp_3]

Output

[wp_ad_camp_4]

Download the codes

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

[wp_ad_camp_5]

You Might Also Like

2 Comments

  1. 1

    Hi – you seem to be missing the Stored Procedure call in your database definition. @Procedure in your PersonRepository is pointing to “addPerson(…)”

  2. 2

Leave a Reply

Your email address will not be published. Required fields are marked *