在哪里可以看到HSQL数据库和表 [英] Where can I see the HSQL database and tables

查看:114
本文介绍了在哪里可以看到HSQL数据库和表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了一个hsqldb.jar并设置为项目buildpath,然后我编写了程序

I have downloaded a hsqldb.jar and I set to project buildpath,then next I wrote the program

  Class.forName("org.hsqldb.jdbc.JDBCDriver");
Connection conn = DriverManager.getConnection(
                     "jdbc:hsqldb:mem:mydb", "SA", "");

String bookTableSQL = "create table MY_TABLE ("+
" TITLE varchar(256) not null primary key,"+
" AUTHOR varchar(256) not null"+
");";

Statement st = conn.createStatement();
st.execute(bookTableSQL);
System.out.println(st);
String sql = "INSERT INTO MY_TABLE " +
"VALUES ('Mahnaz', 'Fatma')";

st.executeUpdate(sql);

数据库和表已成功创建.在下一步中,我插入了一个示例数据,并显示了数据

Database and table created successfully. In the next step, I inserted a sample data and get the data is displaying

String sqlsel = "SELECT TITLE,AUTHOR FROM MY_TABLE";
 ResultSet rs = st.executeQuery(sqlsel);
 //STEP 5: Extract data from result set
 while(rs.next()){
    //Retrieve by column name
     String id  = rs.getString("TITLE");
     String age = rs.getString("AUTHOR");

    //Display values
    System.out.print("ID: " + id);
    System.out.print(", Age: " + age);

 }

我的问题是我没有创建"mydb"数据库. 还可以在哪里看到创建的数据库和表?

My problem is I did not created "mydb" database. Also where can I see the created database and table?

推荐答案

您已经在内存中创建了数据库,因此没有包含表/数据的持久文件,然后关闭应用程序,所有数据都丢失了.

You've created database in memory, so there is no persistent file with your tables / data and then you close your application, all your data lost.

如果要使其永久修复,请修复连接创建:将内存替换为文件.像这样:

If you want to make it persistent fix your connection creation: replace mem to file. Something like this:

Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:mydb", "sa", "");

您可以在此处中了解不同的HSQLDB模式.您也可以指定路径,数据库将在其中存储文件:

You can read about different HSQLDB modes here. Also you can specify path, where your database will store file:

jdbc:hsqldb:file:/file/path/to/test"

第一次运行后,HSQLDB将创建几个文件.您可以在此处阅读.

After first run HSQLDB will create several files. Purpose of each file you can read here.

test.properties 包含条目修改".如果将已修改"项设置为是",则数据库正在运行或未正确关闭(因为关闭算法最后将已修改"设置为否").

test.properties Contains the entry 'modified'. If the entry 'modified' is set to 'yes' then the database is either running or was not closed correctly (because the close algorithm sets 'modified' to 'no' at the end).

test.script 该文件包含组成数据库的SQL语句,直到最后一个检查点-它与test.backup保持同步.

test.script This file contains the SQL statements that makes up the database up to the last checkpoint - it is in synch with test.backup.

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

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

测试备份 这是压缩的文件,其中包含最后一个检查点时旧test.data文件的完整备份.

test.backup This is compressed file that contains the complete backup of the old test.data file at the time of last checkpoint.

test.log 该文件包含自上一个检查点以来已修改数据库的多余SQL语句(类似于重做日志"或事务日志",只是文本).

test.log This file contains the extra SQL statements that have modified the database since the last checkpoint (something like the 'Redo-log' or 'Transaction-log', but just text).


顺便说一句,您可以使用此查询获取所有表格:


BTW, you can get all your tables using this query:

SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES where TABLE_TYPE='TABLE'

您可以像普通查询一样执行此查询:

You can execute this query as normal query:

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES where TABLE_TYPE='TABLE'");

while(rs.next()) {
    ...
}

还可以使用内置管理器查看数据库.您可以开始使用以下命令:

Also you can view your database using built-in manager. You can start in using command:

java -cp /path/to/hsqldb.jar org.hsqldb.util.DatabaseManager 

然后指定数据库路径:

jdbc:hsqldb:file:mydb

或者您可以使用 SQuirreL 之类的流行工具.

Or you can use popular tool like SQuirreL.

这篇关于在哪里可以看到HSQL数据库和表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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