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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
  1. DZone
  2. Data Engineering
  3. Databases
  4. Mule Database Connector With HSQLDB

Mule Database Connector With HSQLDB

Learn how to use the MuleSoft database connector to connect a Mule flow to a HyperSQL (HSQL) database in this integration tutorial.

Mohit Chhabra user avatar by
Mohit Chhabra
·
Sep. 26, 17 · Tutorial
Like (4)
Save
Tweet
Share
4.21K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will let you know how to use the database connector in MuleSoft for HSQLDB. Below are the points of which I will be giving a brief description:

  1. How to install the HSQL database on your system.

  2. The Mule flow to connect to the above-created database.

First, we will have some idea about the HSQL database. HSQLDB (HyperSQL Database) is a relational database engine written in Java. I have used version 2.3.4 in my example. This will not take much of the memory and space on your system and will install easily. Below are the steps:

Download the latest version of the HSQLDB database. I have version 2.3.4 downloaded from this link.

Extract the zip file you downloaded in the C directory.

Create a properties file named server.properties under C:\hsqldb-2.3.4\hsqldb, which defines a new database named Mydemodb with the below property lines:

server.database.0 = file:hsqldb/MyDemodb
server.dbname.0 = testdb

Then execute the below command in the command line:

cd C:\hsqldb-2.3.4\hsqldb
hsqldb>java -classpath lib/hsqldb.jar org.hsqldb.server.Server

outputofserverstart

Once we have created a database, we have to start the database by using the following command:

\>cd C:\hsqldb-2.3.4\hsqldb
hsqldb>java -classpath lib/hsqldb.jar org.hsqldb.server.Server --database.0
file:hsqldb/demodb --dbname.0 testdb

 Now you can open the database GUI with runManagerSwing.bat from the C:\hsqldb-2.3.4\hsqldb\bin location. You will be asked to fill in the connection settings; fill them in as below:

settingshsqldb

Now the database GUI will open and you can create your test tables and insert the data.

Now we will see how we can use this database in our Mule flow.

Create a new Mule project "DB_connector_example." We will be creating a flow like below:

muleflow

 First, insert an HTTP inbound connector listening on 8081 and on path /dbconnector.

Insert a logger to log in a message.

Now, here comes the important part: the database connector. Place a DB connector after the logger and define the global database connector as below:

DB connector_1

Global_conf

Also, add the hsqldb2.3.4 jar file in the referenced libraries so that the driver class name can be looked into that Jar file. Right click on your project -->Build Path-->Add external archive and point to the jar file.referenced jar

Now, if your database is running, you can test the connection in the global test configuration. If that is successfully tested, you may proceed with your flow.TestConnection.PNG

Now, if you will place the last logger ( skipping the Object to JSON Transformer) and run your application you will get the below distorted output.

¬í sr java.util.LinkedList)S]J`ˆ"  xpw   sr $org.mule.util.CaseInsensitiveHashMapÑÙïgEÎ
  xpw?@       t ¬í sr java.util.LinkedList)S]J`ˆ"  xpw   sr $org.mule.util.CaseInsensitiveHashMapÑÙïgEÎ
  xpw?@       t EMPLOYEEIDsr java.lang.Integerâ ¤÷‡8 I valuexr java.lang.Number†¬•”à‹
  xp   {t EMPLOYEENAMEt mohitxsq ~ w?@       q ~ q ~ q ~ q ~ xx

Because the output is java.util.LinkedList, which displays on the client side, it is not converted into any standard message format. To convert it to a JSON format, we will use an Object to JSON Transformer in between the logger and DB connector.

Now save your project and run the application. From any browser, hit http://localhost:8081/dbconnector and hit enter; you will get the data from the table.

fteched output.PNG

Relational database HSQLDB Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • ChatGPT: The Unexpected API Test Automation Help
  • AWS Cloud Migration: Best Practices and Pitfalls to Avoid
  • How to Secure Your CI/CD Pipeline
  • Select ChatGPT From SQL? You Bet!

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: