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

  • Database Connection Pooling at Scale: PgBouncer + Multi-Tenant Postgres (10K Concurrent Connections)
  • Build a Query in MuleSoft With Optional Parameters
  • Monitoring Postgres on Heroku
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

Trending

  • Treat Salesforce Configuration Like Code: Release Discipline in a Copado Pipeline
  • Why Vulnerability Management Fails Without Reliable Asset Data
  • Solving Comprehension Debt in AI-Generated Codebases
  • Part 1: Building Governed MCP Tool Services With Quarkus LangChain4j and Goose

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. MuleSoft: Connect PostgreSQL Database and Call PostgreSQL Function

MuleSoft: Connect PostgreSQL Database and Call PostgreSQL Function

In this article, we will explore how to connect the PostgreSQL database from the Mule application. We will also see how to call the PostgreSQL function.

By 
Saddam Shaikh
·
Feb. 07, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.9K 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

What Is PostgreSQL?

PostgreSQL is an open source object-relational database system that uses and extends the SQL language to store and scale complicated data workloads.

A prerequisite to start with this walkthrough is to have a database connector added in Anypoint Studio. You can add these connectors from the Add modules option. Also, you need to have an ElephantSQL account, as we are going to use the PostgreSQL database hosted on the ElephantSQL platform. You can use any other PostgreSQL service provider platform or self-managed PostgreSQL server.

Let's configure the database connector step by step to connect to PostgreSQL:

  1. Select the Generic Connection from the Connection dropdown.
  2. Click on Configure JDBC Driver and select the Add Maven dependency option.
  3. Search for PostgreSQL dependency. Add it, and click on the Finish button to download the dependency.Search Maven Central
  4. Provide the below connection details to connect to the database instance and click on Test Connection to check connectivity.
    • URL - jdbc:postgresql://<<host>>:<<port>>/<<databaseName>>
    • Driver class name - org.postgresql.Driver
    • User - Username
    • Password - Password Test Connection Successful

          In ElephantSQL, you can get database connection details in the Details section.

ElephantSQL Details

Let's create a PostgreSQL function that will add 2 numbers and return the sum of them. In ElephantSQL's browser section, you can execute SQL script to create a function in PostgreSQL.

Create a function in PostgreSQL


SQL
 
CREATE FUNCTION addition(num1 integer, num2 integer) RETURNS integer
    AS 'select num1 + num2;'
    LANGUAGE SQL
    IMMUTABLE
    RETURNS NULL ON NULL INPUT;


No errors (Console)

Body - Addition

Hope you enjoyed reading this article.

PostgreSQL Database connection MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • Database Connection Pooling at Scale: PgBouncer + Multi-Tenant Postgres (10K Concurrent Connections)
  • Build a Query in MuleSoft With Optional Parameters
  • Monitoring Postgres on Heroku
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

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