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

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.

[  
	{  
		"ID":1,  
		"code1":"test1",  
		"code2":"testing1",  
		"airlineName":"testing1",  
		"toAirport":"testing1",  
		"fromAirport":"testing1",  
		"takeOffDate":"2011/11/11",  
		"price":100,  
		"planeType":"testing1",  
		"setatsAvailable":10,  
		"totalSeats":250  
	},  
	{  
		"ID":2,  
		"code1":"test",  
		"code2":"testing",  
		"airlineName":"testing",  
		"toAirport":"testing",  
		"fromAirport":"testing",  
		"takeOffDate":"2010/10/10",  
		"price":100,  
		"planeType":"testing",  
		"setatsAvailable":10,  
		"totalSeats":250  
	}  
] 

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

Leave a Reply