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. Connect H2 Database to Anypoint Studio [Snippet]

Connect H2 Database to Anypoint Studio [Snippet]

These instructions will help you easily connect H2 database in your Mule flows in Anypoint Studio using the following snippet.

Pavithra Sugumar user avatar by
Pavithra Sugumar
·
Oct. 19, 17 · Tutorial
Like (4)
Save
Tweet
Share
7.57K Views

Join the DZone community and get the full member experience.

Join For Free

After setting up H2 database, if you are stuck with how to configure your H2 database in your Mule flow in Anypoint Studio, then below is the simple and straightforward solution:

H2 database configuration is part of the Generic Database configuration in Anypoint Studio and the following code could be helpful to use in your Mule implementation to connect H2 DB:

<spring:beans>
<spring:bean id="datasource" name="datasource"
class="org.h2.jdbcx.JdbcDataSource">
<spring:property name="URL" value="${url}" />
<spring:property name="user" value="${username}" />
<spring:property name="password" value="${password}" />
</spring:bean>
</spring:beans>

<db:generic-config name="H2_Configuration"
dataSource-ref="datasource" doc:name="Generic Database Configuration" />

Please note:

Sample URL = jdbc:h2:tcp://localhost/~/test

The URL, username, and password (of your choice) could be taken from a properties file and its location mentioned in the Mule configuration file, something like this:

<context:property-placeholder location="yourpropertyfile.properties" />

and it is referenced as  ${url} ,  ${username} , etc in </spring:beans>.

Also, the H2 jar (ex: h2-1.4.196.jar) which is in your H2 installation path\H2\bin needs to be included in your Mule project build path as a prerequisite.

Finally, go ahead and test the connection in the generic database configuration.

Database

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • API Design Patterns Review
  • 13 Code Quality Metrics That You Must Track
  • Using AI and Machine Learning To Create Software
  • Load Balancing Pattern

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: