java - Where can I see the HSQL database and tables -


i have downloaded hsqldb.jar , set project buildpath,then next wrote 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 my_table " + "values ('mahnaz', 'fatma')";  st.executeupdate(sql); 

database , table created successfully. in next step, inserted sample data , data displaying

string sqlsel = "select title,author my_table";  resultset rs = st.executequery(sqlsel);  //step 5: extract data result set  while(rs.next()){     //retrieve column name      string id  = rs.getstring("title");      string age = rs.getstring("author");      //display values     system.out.print("id: " + id);     system.out.print(", age: " + age);   } 

my problem did not created "mydb" database. can see created database , table?

you've created database in memory, there no persistent file tables / data , close application, data lost.

if want make persistent fix connection creation: replace mem file. this:

connection conn = drivermanager.getconnection("jdbc:hsqldb:file:mydb", "sa", ""); 

you can read different hsqldb modes here. can specify path, database store file:

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

after first run hsqldb create several files. purpose of each file can read here.

test.properties contains entry 'modified'. if entry 'modified' set 'yes' database either running or not closed correctly (because close algorithm sets 'modified' 'no' @ end).

test.script file contains sql statements makes database last checkpoint - in synch test.backup.

test.data file contains (binary) data records cached tables only.

test.backup compressed file contains complete backup of old test.data file @ time of last checkpoint.

test.log file contains sql statements have modified database since last checkpoint (something 'redo-log' or 'transaction-log', text).


btw, can tables using query:

select * information_schema.system_tables table_type='table' 

you can execute query normal query:

statement st = conn.createstatement(); resultset rs = st.executequery("select * information_schema.system_tables table_type='table'");  while(rs.next()) {     ... } 

also can view database using built-in manager. can start in using command:

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

and specify path database:

jdbc:hsqldb:file:mydb 

or can use popular tool squirrel.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -