I am looking into HSQL (to embed in an app) and was expecting that the data would be saved in a myDB.data file in the filesystem
Instead after a clean shutdown (execute sql “shutdown”, stop and shutdown server object) the only remaining files are myDB.properties and myDB.script and myDB.script has all the commands to recreate the data in memory. No myDB.data file exists
E.g. from myDB.script
CREATE MEMORY TABLE PUBLIC.DUMMYTABLE(ID INTEGER PRIMARY KEY,FIRSTNAME VARCHAR(20))
From myDB.properties:
version=2.2.4
modified=no
I thought I was using file db and not memory db.
Class.forName("org.hsqldb.jdbc.JDBCDriver");
HsqlProperties p = new HsqlProperties();
p.setProperty("server.database.0", "file:./testDB");
p.setProperty("server.dbname.0","myDB");
p.setProperty("server.address","localhost");
Server server = new Server(); server.setProperties(p);
server.start();
Connection connection = DriverManager.getConnection"jdbc:hsqldb:hsql://localhost:9001/myDB", "SA", "");
PreparedStatement st = connection.prepareStatement("CREATE TABLE dummyTable (id INTEGER PRIMARY KEY, firstname VARCHAR(20))");
st.executeUpdate();
connection.prepareStatement("shutdown").execute();
connection.close();
server.stop();
server.shutdown();
If you use a
file:database, HSQLDB should create.scriptand.properties(and possibly a.logif there is an unexpected shutdown) for your database, and these files will not be removed if the application is shut down. The.scriptfile should have all of the INSERT statements necessary to repopulate your data.If you use a
mem:database, the files will not be written at all, and the data will not be saved between instances. From the guide:The fact that the files exist and remain between application restarts is, in itself, the “file” database that you’re looking for.
Edit:
To answer your comment,
From the guide:
See horse’s answer for information about CACHED vs MEMORY tables. Regarding your questions about when you’d use CACHED tables, here’s another snippet from the guide: