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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Grounding AI Agents in Governed Data
  • Engineering Self-Healing SQL Pipelines With LLMs: Validation, Guardrails, and Safe Recovery

Trending

  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • How to Hide Sensitive Information Before You Share a File
  • Top Gen AI Frameworks for Go in 2026: A Hands-On Comparison
  • The Man Who Invented Selenium Also Built Its Replacement

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Call a Stored Procedure From Mule ESB

Call a Stored Procedure From Mule ESB

In this article, I am going to explain how to call a stored procedure that accepts custom defined table types.

By 
Baranee Manoharan
·
Updated Dec. 17, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
30.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Man talking on cell phone outside

In this article, I am going to explain how to call a stored procedure that accepts custom-defined table types. If you have to send multiple records in a single time to the DB from your front end, that's where we use custom defined table types. 

These types allow multiple rows, which contain different data types like varchar, boolean, etc.

I have a table type below:

SQL
x
11
 
1
USE [myown] GO 
2
/****** Object: UserDefinedTableType [dbo].[tblcustomers] Script Date: 6/2/2018 4:11:08 PM ******/
3
create TYPE [dbo].[tblcustomers] AS TABLE(
4
  [Title] [nvarchar](8) NULL, 
5
  [Suffix] [nvarchar](10) NULL, 
6
  [CompanyName] [nvarchar](128) NULL, 
7
  [SalesPerson] [nvarchar](256) NULL, 
8
  [EmailAddress] [nvarchar](50) NULL, 
9
  [PasswordHash] [nvarchar](128) NOT NULL, 
10
  [PasswordSalt] [nvarchar](10) NOT NULL
11
) GO


A stored procedure, which has table typed parameter is as follows:

SQL
xxxxxxxxxx
1
 
1
USE [myown] GO create PROCEDURE [dbo].[fetchtblCusomters](
2
  @tblcustomers tblcustomers READONLY
3
) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON -- Insert statements for procedure here select * from @tblcustomers END


Now we have to call this stored procedure in Mule, and my flow looks like below:

Image title

XML
xxxxxxxxxx
1
26
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<mule
3
    xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
4
    xmlns:db="http://www.mulesoft.org/schema/mule/db"
5
    xmlns:json="http://www.mulesoft.org/schema/mule/json"
6
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
7
    xmlns="http://www.mulesoft.org/schema/mule/core"
8
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
9
    xmlns:spring="http://www.springframework.org/schema/beans"
10
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
11
    <db:generic-config name="Generic_Database_Configuration" url="jdbc:sqlserver://baraneesql.database.windows.net:1433;database=myown;user=baranee@baraneesql;password=****;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" doc:name="Generic Database Configuration"></db:generic>
12
    <flow name="tabletypeflow">
13
        <http:listener config-ref="HTTP_Listener_Configuration" path="/tabletype" allowedMethods="GET" doc:name="HTTP"></http:listener>
14
        <set-variable variableName="records" value="#[new com.microsoft.sqlserver.jdbc.SQLServerDataTable();]" doc:name="Variable"></set>
15
        <expression-component doc:name="create-records">
16
            <![CDATA[records.addColumnMetadata("Title" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("Suffix" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("CompanyName" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("SalesPerson" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("EmailAddress" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("PasswordHash" ,java.sql.Types.NVARCHAR); records.addColumnMetadata("PasswordSalt" ,java.sql.Types.NVARCHAR); records.addRow('Dr', 'Hr', 'Mindtree', 'tiptop', '[email protected]', '', ''); ]]>
17
        </expression-component>
18
        <db:stored-procedure config-ref="Generic_Database_Configuration" doc:name="Database">
19
            <db:parameterized-query>
20
                <![CDATA[{CALL fetchtblCusomters(:tblcustomers )}]]>
21
            </db:parameterized-query>
22
            <db:in-param name="tblcustomers" value="#[flowVars.records]"></db:in>
23
        </db:stored-procedure>
24
        <json:object-to-json-transformer doc:name="Object to JSON"></json:object>
25
    </flow>
26
</mule> 

Mule Steps 

  1. Create a flow Variable object for the class SQLServerDataTable

  2. Add columns to the table type object you have created.

    1. records.addColumnMetadata("Suffix" ,java.sql.Types.NVARCHAR); — In here, Suffix is a column table and it is NVARCHAR SQL type

    2. Once you are done adding columns, add rows to the table

      1. records.addRow('Dr', 'Hr', 'Mindtree', 'tiptpop', '[email protected]', '', '');

    3. Now, using database connector, call the Stored Procedure, which has table type parameter.    

Image title

Your SQL Server DB connection will be:

Image title

That's it, you have your multiple records flying through to SQL Server DB in a single time.

Database Enterprise service bus sql

Opinions expressed by DZone contributors are their own.

Related

  • MySQL Instant DDL: Metadata Locks, Waiting Writers, and Query Pileups
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Grounding AI Agents in Governed Data
  • Engineering Self-Healing SQL Pipelines With LLMs: Validation, Guardrails, and Safe Recovery

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook