0

I am working with a Spring MVC web application that simulates an in-memory persistence layer using a combination of Maps, Lists, etc. Obviously, a database is much more performant, so I want to use HSQLDB. I want the database to be embedded from the standpoint of being accessible only via the application and starting/stopping with the web application. But I want the data to be permanent, i.e. file-based so even if the application is restarted, the data is loaded from a file. Is there a way to achieve this?

Note (added 4/28/2015): I want this to work in the following way:

  1. Web application starts up
  2. Web application checks presence of database (file) in configured location
  3. If database is not available at configured location, it creates by running a provided SQL initialization script.

I added the following to my Spring configuration file:

<bean id="embeddedDataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    <property name="url" value="jdbc:hsqldb:file:/usr/local/data/hsqldb/testdb" />
    <property name="username" value="sa" />
    <property name="password" value="" />
</bean>

But I don't see any database file created at the location /usr/local/data/hsqldb/

Web User
  • 7,438
  • 14
  • 64
  • 92
  • 1
    Just create a `DataSource` bean with the appropriate properties. For file based HSQLDB, take a look at HSQL documentation: you only need to change the URL of the DB to make it file-persistent. – Guillaume Polet Apr 25 '15 at 08:58
  • @GuillaumePolet I added a `datasource` configuration to my Spring configuration file but I did not see any database file created at the given location. Please review the note I added in my question. Thanks. – Web User Apr 28 '15 at 15:32
  • It is a possible duplicate of http://stackoverflow.com/questions/1380882/how-to-embed-hsqldb-in-file-with-spring-to-a-webapp Note: My reputation does not allow me to add a comment, so posted in answer section. – K139 Apr 24 '15 at 18:54

0 Answers0