嵌入式HSQLDB将数据持久保存到文件中 [英] Embedded HSQLDB persist data to a file

查看:91
本文介绍了嵌入式HSQLDB将数据持久保存到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用嵌入式hsqldb的基于spring的Web应用程序. 我的spring配置非常简单:

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>

但是使用此配置,所有数据都存储在内存中.这是创建的数据源URL

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.

推荐答案

此解决方案对我有用

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

这篇关于嵌入式HSQLDB将数据持久保存到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆