Bulk-insert using Database connector
In this article, I will explain how to implement the bulk insert operation in the Mule 4 Database Connector. For instance, we have a json Input payload that contains a list of people. Our interface will read that input file and insert the person data to a mySQL Database Table using Bulk Insert.
HTTP Listener configuration:
Go to Global elements->create->select the HTTP LISTNER
Transform Message(Dataweave 2.0): This component will transform the CSV Data into a JSON format. The field name in the Dataweave will be the parameter name in our Database Connector Insert Query.
Database Connector (Bulk Insert): This Database Connector will execute the Bulk Insert Operation with the parameters from the payload(application/json).
Setup-Database in clever-cloud:
- Use this link to signup clever-cloud:-----https://www.clever-cloud.com/->
- Provide all the required details and login to the clever-cloud
- Create your organization:
- Create an add-on:
- Select the Add-on according to your requirements ,here am adding mysql add-on
- Provide the name of your mysql add-on
Save the configuration details of Your ad-on
- Database configuration:
By using your addon database configuration details configure the database in Any point studio
- Click on phpmyadmin to create your database in clever-cloud
- Create table in clever-cloud Database :
Sql–query for bulk insert:
- Write the sql query to insert the data into the database
INSERT INTO details (Firstname,Middlename,Lastname,Emailid,Country) VALUES (:firstname,:middlename,:lastname,:emailid,:country)
- Save and deploy the application, after successful deployment Hit the url from Postman
Test Result:
Database Table is now having 163 records.
