iBATIS Stored Procedures - iBATIS

How to create a stored procedure?

This chapter explains about how to call a stored procedure using iBATIS configuration. For this you need to learn how to create a stored procedure in MySQL.

We have the following EMPLOYEE table in MySQL −

Let’s create the following stored procedure in MySQL database −

Now consider the EMPLOYEE table has two records as follows −

Employee POJO Class

You need not required to modify the Employee.java file. Let’s be as same as in the last chapter.

Employee.xml File

Here we would modify Employee.xml to introduce <procedure></procedure> and <parameterMap></parameterMap> tags. Here <procedure></procedure> tag would have an id which we would use in our application to call the stored procedure.

IbatisSP.java File

This file has application level logic to read the names of the employees from the Employee table using ResultMap −

Compilation and Run

Following steps are required to compile and run the above-mentioned software. It is mandatory to set PATH and CLASSPATH appropriately before proceeding for compilation and execution.

  • Create Employee.xml as shown above.
  • Create Employee.java as shown above and compile it.
  • Create IbatisSP.java as shown above and compile it.
  • Execute IbatisSP binary to run the program.

After executing the above you will get the following result −

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

iBATIS Topics