Mule with Stored Procedure

Facebooktwittergoogle_plusredditpinterestlinkedinmail

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

So, we will get into our database and create a Stored Procedures there. In our case we will use MS SQL.

Let’s create Stored Procedure by following way :

sp1

 

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 :-

sptest2

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 :-

Untitled

We can see here we are using Mule database component to call this Stored Procedure and passing 2 input parameter and 1 output parameter to display the result.

The corresponding Mule flow in graphical will be as following:-

Untitled

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 :-

console

We can see here the Stored Procedure is called and we are getting the total value from our Mule application.

Conclusion

As we can see it’s very simple to call any Stored Procedure from our Mule application as the database component of Mule supports diverse SQL operations and Stored Procedures on our Database.

That’s all !!! I’ve hopefully been clear enough in displaying the implementation of database component and calling Stored Procedure from our Mule application.

I hope you liked this !!!

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Anirban Sen Chowdhary

Anirban Sen Chowdhary is an information technology professional currently working on Java/J2ee, Esb and Integration platform. For more information, please visit http://anirbansenchowdhary.com and you can also follow https://twitter.com/Anir37

You may also like...

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>