DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Kafka JDBC Source Connector for Large Data
  • How to Integrate a Distributed Database With Event Streaming
  • Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector
  • Amazon Dynamo DB Connector Operations Walkthrough in Mule 4, Part 1

Trending

  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • Event-Driven Architectures: Designing Scalable and Resilient Cloud Solutions
  • AI, ML, and Data Science: Shaping the Future of Automation
  1. DZone
  2. Data Engineering
  3. Databases
  4. Mule 4: Database Connector (Part 2)

Mule 4: Database Connector (Part 2)

Read this tutorial in order to learn how to stream in Mule 4 as opposed to Mule 3. Also learn how to insert, update, and delete operations.

By 
Pryank Gupta user avatar
Pryank Gupta
·
May. 23, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
21.8K Views

Join the DZone community and get the full member experience.

Join For Free

Dynamic Queries:

To get rid of SQL Injection, we need to parameterize the "where" clause in our SQL query. What do we need to do when we don't only need to parameterize the "where" clause but also parts of the query? In Mule 3, we can't achieve this as in Mule 4 from the DB connector drop down. We need to select that we are using Dynamic query or parameterized. You have to choose between having a dynamic query and parameterized. In Mule 4 DB connector, we can use parameterized "where" clause and parts of the query simultaneously. In this example, you can see how a full expression is used to produce the query by building a string in which the table depends on a variable. An important thing to notice is that although the query text is dynamic, it is still using input parameters:

<set-variable variableName="table" value="EMPLOYEE"/>
<db:select config-ref="dbConfig">
 <db:sql>#["SELECT * FROM $(vars.table) WHERE name = :name"]</db:sql>
 <db:input-parameters>
   #[{'name' : payload}]
 </db:input-parameters>
</db:select>

Here comes the question, "Can we use dynamic queries here even though we can also declare table name as Input Parameter?" The answer is no. Input Parameters can only be applied to parameters in a "where" clause. To modify any other part of the query, you need to use DW’s operator.

Streaming Large Results:

Database results can be huge. One single query might return millions of records. Streaming is a recommended solution for this. What does streaming mean? Suppose you have a query that returns 20K rows. Attempting to fetch all those rows at once will result in the following:

  • Performance degradation, since that’s a big pull from the network.
  • A risk of causing out of memory, since all that information needs to be loaded into application memory.

Streaming means that the connector will not fetch the 20K rows at once; instead, it will fetch a smaller chunk, and once that chunk has been consumed, it will go fetch the rest. That way, you can reduce enhance the performance of your flow.

Streaming in Mule 4 vs Streaming in Mule 3:

In Mule 3, this was something you had to specifically enable because it was disabled by default. In Mule 4, this is enabled by default, so you don’t have to worry about it anymore. You can simply trust that the feature is already there.

Insert, Update, and Delete Operations :

The insert, update, and delete operations were also upgraded in Mule 4 DB connector. You can use DataWeave parameters and get dynamic queries as well:

<db:insert config-ref="dbConfig">
  <db:sql>
    INSERT INTO EMPLOYEE(EMPLOYEE_ID, NAME, DESCRIPTION) VALUES (777, 'Pryank', :description)
  </db:sql>
  <db:input-parameters>
    #[
    {'description' : payload}
    ]
  </db:input-parameters>
</db:insert>
<db:update config-ref="dbConfig">
  <db:sql>
    UPDATE EMPLOYEE SET DESCRIPTION = :description where EMPLOYEE_ID = :employeeId
  </db:sql>
  <db:input-parameters>
  #[
    {'description' : payload,
    'employeeId' : 7,
    }
  ]
  </db:input-parameters>
</db:update>
<db:delete config-ref="dbConfig">
  <db:sql>
    DELETE FROM EMPLOYEE where EMPLOYEE_ID = :employeeId
  </db:sql>
  <db:input-parameters>
  #[
    {'employeeId' : 7}
  ]
  </db:input-parameters>
</db:delete>

Hope this helps! Keep learning!

Database Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Related

  • Kafka JDBC Source Connector for Large Data
  • How to Integrate a Distributed Database With Event Streaming
  • Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector
  • Amazon Dynamo DB Connector Operations Walkthrough in Mule 4, Part 1

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!