Sanjeev
Sanjeev

Reputation: 417

Data is not saving in MEMORY table of HSQL

I have created a MEMORY table in HSQL. But the data is saved and accessed only in the running of my Java application.In HSql FAQ they said that,

...the default, MEMORY tables are persistent.

The data is not persistent after the program exists. What is the problem here?

SQL:

CREATE MEMORY TABLE SESSIONS(
    SESSION_DATE DATE NOT NULL,
    IN_TIME TIMESTAMP NOT NULL,
    OUT_TIME TIMESTAMP NOT NULL)

Java :

DriverManager.getConnection("jdbc:hsqldb:file:"+
    DbConnection.class.getResource("/loginTimerDB").getPath()+"/loginTimerDB",
    "SA",
    "");

I have placed this database file within java packages to make a simple jar file while deploying.

Ok. at first I have the same thought about packing database in jar file. so I have moved that hsql database folder, to out side of the source packages. And, I have changed the java code like below,

"jdbc:hsqldb:file:loginTimerDB/loginTimerDB"

I have previously worked with hsql db, and never had a problem like this.

Upvotes: 1

Views: 2950

Answers (2)

palacsint
palacsint

Reputation: 28845

Are you closing the database before your application exits? Regarding to the Hsqldb User Guide, Closing the Database, you have to send a SHUTDOWN command via the JDBC connection

connection.prepareStatement("SHUTDOWN").execute();

or set the shutdown=true property in the connection string:

jdbc:hsqldb:file:loginTimerDB/loginTimerDB;shutdown=true

Upvotes: 1

fredt
fredt

Reputation: 24352

When you put a database in a jar, it become readonly.

In your deployment, you can extract the database into a separate directory with read/write permissions before accessing it.

Upvotes: 1

Related Questions