关于数据保存的HSQL问题 [英] hsql question on data being saved

查看:91
本文介绍了关于数据保存的HSQL问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究HSQL(嵌入到应用程序中),并期望将数据保存在文件系统中的myDB.data文件中.
而是在彻底关闭(执行sql关闭",停止并关闭服务器对象)之后,剩下的唯一文件是myDB.properties和myDB.script,而myDB.script拥有所有用于在内存中重新创建数据的命令.不存在myDB.data文件
例如.来自myDB.script

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))

从myDB.properties:

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();

推荐答案

如果使用file:数据库,则HSQLDB应该创建.script.properties(如果意外关闭,则可能创建.log)数据库,并且如果应用程序关闭,这些文件也不会被删除. .script文件应具有重新填充数据所需的所有INSERT语句.

If you use a file: database, HSQLDB should create .script and .properties (and possibly a .log if there is an unexpected shutdown) for your database, and these files will not be removed if the application is shut down. The .script file should have all of the INSERT statements necessary to repopulate your data.

如果使用mem:数据库,则将根本不会写入文件,并且不会在实例之间保存数据.从指南:

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:

由于没有信息写入磁盘, 此模式应仅用于 申请的内部处理 小程序或某些特殊数据 应用程序.指定此模式 通过内存:协议.

As no information is written to disk, this mode should be used only for internal processing of application data, in applets or certain special applications. This mode is specified by the mem: protocol.

文件存在并在应用程序重新启动之间保留的事实本身就是您要查找的文件"数据库.

The fact that the files exist and remain between application restarts is, in itself, the "file" database that you're looking for.

要回答您的评论,

但是在这种情况下,手册所使用的* .data文件是

But in which case is the *.data file used that the manual mentions

摘录自指南:

此文件仅包含CACHED表的(二进制)数据记录.

This file contains the (binary) data records for CACHED tables only.

请参阅马的答案以了解有关CACHED与MEMORY的信息桌子.关于您何时使用CACHED表的问题,这是来自的另一个代码段指南:

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:

他们的数据或索引中只有一部分是 保存在内存中,允许使用大表 否则会占用 几百兆的内存. 缓存表的另一个优点是 数据库引擎花费更少 缓存表的启动时间 用于大量数据.这 缓存表的缺点是 降低速度.不要使用缓存 表,如果您的数据集相对 小的.在一些应用中 小桌子和一些大桌子 最好使用默认值MEMORY 小表的模式.

Only part of their data or indexes is held in memory, allowing large tables that would otherwise take up to several hundred megabytes of memory. Another advantage of cached tables is that the database engine takes less time to start up when a cached table is used for large amounts of data. The disadvantage of cached tables is a reduction in speed. Do not use cached tables if your data set is relatively small. In an application with some small tables and some large ones, it is better to use the default, MEMORY mode for the small tables.

这篇关于关于数据保存的HSQL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆