Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Are your API program basics covered? Read the 5 Pillars of Full Lifecycle API Management eBook

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.

Establish API creation, publishing and discovery as a master practice with the API Management Playbook.

Topics:
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 }}