Data is not saving in MEMORY table of HSQL

南楼画角 提交于 2019-12-24 12:18:12

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/7397775/data-is-not-saving-in-memory-table-of-hsql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!