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
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
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal

Trending

  • Implementing Observability in Distributed Systems Using OpenTelemetry
  • 5 Common Security Pitfalls in Serverless Architectures
  • Exactly-Once Processing: Myth vs Reality
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  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 user avatar
Saddam Shaikh
·
Feb. 07, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
16.3K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal

Partner Resources

×

Comments

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

  • 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