Today we will be discussing on how to connect database ( I'll be using MYSQL) with Mule USB micro services. Basically you may create a service to perform GET, POST, PUT and DELETE operations and make changes to the db accordingly.
In this tutorial I'll show how to fetch data from a table in the form of XML. It's pretty easy - what all you need to do is follow the below steps-
Step-1: Entire project structure should be looking like below image. We need to use HTTP, Variable, Database and Object to XML component to perform this operation. I'll explain the each component structure in the following steps.
Step-2: HTTP component should be used for as usual request/response handler over the browser. HTTP structure should be looking like below image - Make sure you have mentioned the path and allowed method as shown below-
Step-3: Now we will be setting up Variable component as operation Set Variable. Value should be like #[message.inboundProperties.'http.query.params'.currency_from]. currency_from is the column name in DB which will be supplied via browser get parameter.
Step-4: Below is the DB module - operation is set to be Select and query is to select all from Exchange_value table. I am assuming you have already installed the MYSQL DB and build the table Exchange_value with all the columns as shown in below query.
Step-5: Below image shows about your DB connection param/urls. Make sure you have entered all correctly and also imported MYSQL DRIVER JAR file as highlighted in below image.
Step-6: Add object to XML as shown in below image.
Step-7: Now we will execute the project and test the service over the browser/postman tool.
Lets browse the URL http://localhost:8081/db?currency_from=USD
You should get the below result -
Lets compare the same with table query data -
In this tutorial I'll show how to fetch data from a table in the form of XML. It's pretty easy - what all you need to do is follow the below steps-
Step-1: Entire project structure should be looking like below image. We need to use HTTP, Variable, Database and Object to XML component to perform this operation. I'll explain the each component structure in the following steps.
Step-2: HTTP component should be used for as usual request/response handler over the browser. HTTP structure should be looking like below image - Make sure you have mentioned the path and allowed method as shown below-
Step-3: Now we will be setting up Variable component as operation Set Variable. Value should be like #[message.inboundProperties.'http.query.params'.currency_from]. currency_from is the column name in DB which will be supplied via browser get parameter.
Step-4: Below is the DB module - operation is set to be Select and query is to select all from Exchange_value table. I am assuming you have already installed the MYSQL DB and build the table Exchange_value with all the columns as shown in below query.
Step-5: Below image shows about your DB connection param/urls. Make sure you have entered all correctly and also imported MYSQL DRIVER JAR file as highlighted in below image.
Step-6: Add object to XML as shown in below image.
Step-7: Now we will execute the project and test the service over the browser/postman tool.
Lets browse the URL http://localhost:8081/db?currency_from=USD
You should get the below result -
Lets compare the same with table query data -
ReplyDeleteThanks for sharing this blog.This article gives lot of information.
Mulesoft Online Training
Mulesoft Training in Hyderabad
Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging. This article is very much helpful and i hope this will be an useful information for the needed one.Keep on updating these kinds of informative things.
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
oracle online training
hadoop training in chennai
hadoop training in bangalore