Over a million developers have joined DZone.

Connect H2 Database to Anypoint Studio [Snippet]

DZone 's Guide to

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.

· Integration Zone ·
Free Resource

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:bean id="datasource" name="datasource"
<spring:property name="URL" value="${url}" />
<spring:property name="user" value="${username}" />
<spring:property name="password" value="${password}" />

<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.

mulesoft ,mule ,anypoint studio ,integration ,h2 database

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}