I want to use HSQLdb for my Spring-based web application, and I want to have the data persistent (so in-memory is out). According to the hsqldb documentation , I can use variables in the connection URL - but the document doesn't say how to set these.
I've read this question , and there are some interesting tactics, such as creating a listener to set properties when the context loads.
This question explains how to get an appropriate location, so I've combined the two approaches. I've tried using a listener to set a new property with the path lifted from javax.servlet.context.tempdir
(it's a File
), I've tried using that property directly. Neither approach works.
One punter has commented that one could set user.home
via a listener, then use ~
in the HSQLdb URL. I've not tried this, but even if it does work, it strikes me as a little yuck, as I redefine something I potentially don't want to. I'm looking for the "proper" way. How do I set that which the HSQLdb calls "web application properties"? (Or is there one that would be suitable?)
From the documentation:
If the database URL contains a string in the form of
${propname}
then the sequence of characters is replaced with the system property with the given name. For example you can use this in the URL of a database that is used in a web application and define the system property,"propname"
in the web application properties. In the example below, the string${mydbpath}
is replaced with the value of the property,mydbpath
From reading the source code, System.setProperty(key, value)
Kicking myself - my issue was first an ancient version of HSQLdb then it wasn't unloading - a restart of Tomcat, and everything started working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.