Mule’s database component allows us to connect with almost any Java Database Connectivity (JDBC) relational database and it has wonderful capabilities to perform various functionalities and run diverse SQL operations on our database, including Select, Insert, Update, Delete, and even Stored Procedures.
We will have a look here on how to use Stored Procedures with our Mule database component. So, before we start using Stored Procedures in our Mule, we will create a Stored Procedures in the database and then call to from our Mule application.
Creating a Store Procedure
Let’s create Stored Procedure by following way :
Here, as we can see we have created a Stored Procedure called SP_TEST, which will take 2 inputs variable V1 and V2 and will sum it and return the total variable after adding both the variables. After our Stored Procedure has been created successfully we will test it in following way :-
We can see here, we are passing 2 integer values in the input variables V1 and V2, and it’s coming out with the total value as output with the addition of these 2 variables.
Stored Procedure with Mule
So, now we will try to call this Stored Procedure from our Mule application in following way :-
The corresponding Mule flow in graphical will be as following:-
Testing our application
Now, we are done with our coding and will deploy our application and test it.
So, now if we will hit the url :- http://localhost:8081/test/test in browser, we will get the following result in Mule console :-
We can see here the Stored Procedure is called and we are getting the total value from our Mule application.
I hope you liked this !!!