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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

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

Related

  • How to Restore a Transaction Log Backup in SQL Server
  • How to Attach SQL Database Without a Transaction Log File
  • A Deep Dive into Apache Doris Indexes
  • Spring Boot Sample Application Part 1: Introduction and Configuration

Trending

  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  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 user avatar
Baranee Manoharan
·
Updated Dec. 17, 19 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
30.1K Views

Join the DZone community and get the full member experience.

Join For Free

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', 'helllo.rai@gmai.com', '', ''); ]]>
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', 'helllo.rai@gmai.com', '', '');

    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

  • How to Restore a Transaction Log Backup in SQL Server
  • How to Attach SQL Database Without a Transaction Log File
  • A Deep Dive into Apache Doris Indexes
  • Spring Boot Sample Application Part 1: Introduction and Configuration

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!