December 28, 2019

How to connect to MySQL table and transform it to JSON using MuleSoft?

1. Create a simple project as below.



2. Listener Configuration is below


3. Select configuration.

Note:
a. Download MySQL connector - https://dev.mysql.com/downloads/connector/j/.
b. Select Local file and add it.
c. The password is also mule.


4. Transform Configuration.

a. Create a json file with the below.

  1. [  
  2. {  
  3.     "ID":1,  
  4.     "code1":"test1",  
  5.     "code2":"testing1",  
  6.     "airlineName":"testing1",  
  7.     "toAirport":"testing1",  
  8.     "fromAirport":"testing1",  
  9.     "takeOffDate":"2011/11/11",  
  10.     "price":100,  
  11.     "planeType":"testing1",  
  12.     "setatsAvailable":10,  
  13.     "totalSeats":250  
  14. },  
  15. {  
  16.     "ID":2,  
  17.     "code1":"test",  
  18.     "code2":"testing",  
  19.     "airlineName":"testing",  
  20.     "toAirport":"testing",  
  21.     "fromAirport":"testing",  
  22.     "takeOffDate":"2010/10/10",  
  23.     "price":100,  
  24.     "planeType":"testing",  
  25.     "setatsAvailable":10,  
  26.     "totalSeats":250  
  27. }  
  28. ]  

b. While adding metadata type, use the json file created in above step.

c. Drag and drop to match.



5. Logger Configuration.


6. Run the application.

Output:

Open http://localhost:8081/db in the browser to view the result from the table


No comments:

Post a Comment