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.

img
HTTP Listener configuration:

Go to Global elements->create->select the HTTP LISTNER

img
img
img
img

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.

img

Database Connector (Bulk Insert): This Database Connector will execute the Bulk Insert Operation with the parameters from the payload(application/json).

img
Setup-Database in clever-cloud:
  • Use this link to signup clever-cloud:-----https://www.clever-cloud.com/->
img
  • Provide all the required details and login to the clever-cloud
img
  • Create your organization:
img
  • Create an add-on:
img
img
  • Select the Add-on according to your requirements ,here am adding mysql add-on
img
  • Provide the name of your mysql add-on
img

Save the configuration details of Your ad-on

img
  • Database configuration:

By using your addon database configuration details configure the database in Any point studio

img
img
  • Click on phpmyadmin to create your database in clever-cloud
img
  • Create table in clever-cloud Database :
img
img
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)

img
  • Save and deploy the application, after successful deployment Hit the url from Postman
img
img

Test Result:

img

Database Table is now having 163 records.

img
icon png
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.

Post a comment

Your email address will not be published.