Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded HSQLDB persist data to a file

I am creating a spring based web application that uses embedded hsqldb. My spring config is pretty simple:

<jdbc:embedded-database id="dataSource" type="HSQL" >
    <jdbc:script location="classpath:scripts/create-table-if-not-exists" />
</jdbc:embedded-database>

But with this config all data is stored in memory. Here is the data source url that is created

jdbc:hsqldb:mem:dataSource

I need to persist data to a file. So that I can use it again after server restart.

like image 322
user1745356 Avatar asked Jul 18 '14 10:07

user1745356


1 Answers

This solution worked for me

<bean class="org.apache.commons.dbcp2.BasicDataSource" id="dataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc:hsqldb:file:#{systemProperties['user.home']}/db/data" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>

<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:scripts/create-table-if-not-exists" />
</jdbc:initialize-database>
like image 151
user1745356 Avatar answered Oct 13 '22 06:10

user1745356