| operating mode |
Description |
Start Command |
JDBC Example |
| Memory (memory-only) mode |
All data is manipulated in memory. The data is destroyed after the application exits.
No need to start HSQLDB Server separately |
Start Mode 1: The first call through the program connection C = drivermanager.getconnection ("Jdbc:hsqldb:mem:myDbName", "sa", "");
Start Mode 2: You can also specify the same URL in server.properties to run a memory-only (in-memory only) server instance. |
Jdbc:hsqldb:mem:myDbName |
|
Process in-process (Standalone) mode
The database engine runs in the same JVM as part of the application |
Start the database from the application. Because all data is written to the file, the data is not destroyed even after the application exits.
No need to start HSQLDB Server separately |
As with memory-only mode, in-process does not need to be started separately, through Drivermanager.getconnection (Jdbcuriname, "sa", ""); |
The path format of the database file is specified with a forward slash ("/") on both the Linux host and the Windows host
Jdbc:hsqldb:file:/c:/mydb/mydbname Jdbc:hsqldb:file:/opt/db/mydbname
Jdbc:hsqldb:file:myDbName
|
| Server mode |
In this mode, HSQLDB is started as a server in the same way as other database servers. |
by JAVA-CP. /lib/hsqldb.jar org.hsqldb.server-database.0 mydb-dbname.0 Mydbname and other commands to start the hsqldb daemon. |
Jdbc:hsqldb:hsql://localhost:9001/mydbname |
| Web server Mode |
The mode HSQLDB is started as a Web server and accepts client commands through the HTTP protocol. Starting with 1.7.2, the HSQLDB of the Web server pattern begins to support transactions. |
JAVA-CP. /lib/hsqldb.jar org.hsqldb.webserver-database.0 mydb-dbname.0 Mydbname |
- |
http://blog.csdn.net/youlianying/article/details/4217292
Hsqldb can be run in several different ways. However, it can be broadly divided into Serer mode and in-process (in-process mode, also known as standalone (standalone) mode). For each mode, the jar has a corresponding subroutine to run the HSQLDB.
Each HSQLDB database contains 2 to 5 files with the same name but different extensions, which are located in the same directory. For example, the database Fame "test" contains the following files: Test.properties test.script test.log test.data test.backup
The properties file describes the basic configuration of the database.
The script file records the definition of tables and other database objects, as well as the data for non-cached (unbuffered) tables.
Log files are used to record changes in the database and are removed when the hsqldb is closed normally. Otherwise (at an abnormally exited time), it will be used to repeat the update operation recorded in "Test.log" the next time the HSQLDB is started.
The data file contains cached (buffered) tables.
The backup file compresses the data file, and it contains the last final state of the file. All of these documents are essential and must not be removed without authorization. However, if your database does not have a buffer table (cached table), the Test.data and test.backup files will not exist. In addition, the HSQLDB database can be linked to any formatted text file, such as a CSV list, anywhere on the disk.
The Lck file can also be used to record whether the database is open, which is removed when the hsqldb exits normally. In some cases, HSQLDB will generate Test.data.old "files, but they will be deleted later.
http://blog.itpub.net/47598/viewspace-22397/
JAVA-CP. /lib/hsqldb.jar org.hsqldb.server-database.0 testdb-dbname.0 Testdbname
[-database.0], [dbname.0] Why in the back add [0]. _... ... We are not saying in front of the service mode can specify 10 database when running, if there are multiple databases, continue to write command line parameters-database.1 aa-dbname.1 aa-database.2 bb-dbname.2 BB ...
http://cxh61207.iteye.com/blog/904444
In-process (standalone) mode:
There are 2 characteristics of this model.
The first feature, as the name implies, standalone. That is, the database can exist independently of anything else, including the database engine. The data of this pattern can be persisted compared to the in-memory mode, and the form is a few files. and server mode, to use this mode of the database does not need to start any server or monitoring.
The second characteristic, also can be as the name implies, In-process. In this mode, the database engine and the application run in a JVM. For most applications, this mode can speed up because the data no longer needs to be transferred across the network. But there is also a drawback to this approach, which is that programs outside the process, such as database Manager, cannot see the data in the databases.
HSQLDB Official recommendation: In the development of the server mode, when deployed to the actual production environment when the standalone mode.
By default, the data is also stored in memory, and if you want to persist the data, you need to execute the HSQLDB command SHUTDOWN before shutting down the VM.
http://pupi.iteye.com/blog/45272
http://blog.csdn.net/luxideyao/article/details/19834959
http://maimode.iteye.com/blog/1415644
Http://www.cnblogs.com/kenkofox/archive/2010/12/01/1893782.html
Memory Mode:
Packagedb.hsqldb;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;ImportJava.sql.ResultSetMetaData;Importjava.sql.SQLException;Importjava.sql.Statement; Public classHsqldbdemo { Public Static voidMain (string[] args)throwsClassNotFoundException, SQLException {//loading the hsqldb JDBC driverClass.forName ("Org.hsqldb.jdbcDriver"); //Establish database Memdb in memory, user name SA, password is emptyConnection conn = drivermanager.getconnection ("Jdbc:hsqldb:mem:memdb", "username", "password"); Statement Stat=conn.createstatement (); //New data TableStat.executeupdate ("CREATE TABLE Person" (NAME VARCHAR (a), Age integer,estate DECIMAL (15,6)) "); System.out.println ("Create Table:person OK"); //Inserting DataStat.executeupdate ("INSERT into person VALUES (' TPP ', 22,0.3)"); Stat.executeupdate (INSERT into Person VALUES (' WTO ', ' 25 ', 0.5) '); System.out.println ("Insert data into Table:person ok!"); Conn.close (); //Stat.execute ("SHUTDOWN");conn = Drivermanager.getconnection ("Jdbc:hsqldb:mem:memdb", "username", "password"); //Querying DataPreparedStatement pstmt = conn.preparestatement ("SELECT * FROM Person"); ResultSet RS=Pstmt.executequery (); ResultSetMetaData RSMD=Rs.getmetadata (); while(Rs.next ()) { for(inti = 1; I <= rsmd.getcolumncount (); i++) {System.out.print (Rsmd.getcolumnlabel (i)+ ":" + rs.getstring (i) + ""); } System.out.println (""); } }}
Output:
Create Table:person Okinsert data into Table:person OK! NAME:TPP Age: estate:0.300000 name:wto age : estate:0.500000
Server mode:
Directory structure:
│runserver.bat
│
├─data
└─lib
Hsqldb.jar
Runserver.bat:
-classpath. /lib/hsqldb.jar org.hsqldb.server.server-port 9001-database.0 file:.. /data/mydb-dbname.0 MyDB
Packagedb.hsqldb;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;ImportJava.sql.ResultSetMetaData;Importjava.sql.SQLException;Importjava.sql.Statement; Public classHsqldemo { Public Static voidMain (string[] args)throwsClassNotFoundException, SQLException {class.forname ("Org.hsqldb.jdbcDriver"); Connection Conn= Drivermanager.getconnection ("Jdbc:hsqldb:hsql://localhost:9001/mydb", "sa", "" "); System.out.println ("Connected db success!"); String SQL= "CREATE TABLE tbl_users (ID INTEGER, NAME VARCHAR (), BIRTHDAY DATE);"; Statement St=conn.createstatement (); St.execute (SQL); SQL= "INSERT into Tbl_users (ID, NAME, BIRTHDAY) VALUES (' 1 ', ' ADMIN ', sysdate);"; St.executeupdate (SQL); PreparedStatement pstmt= Conn.preparestatement ("SELECT * from Tbl_users"); ResultSet RS=Pstmt.executequery (); ResultSetMetaData RSMD=Rs.getmetadata (); while(Rs.next ()) { for(inti = 1; I <= rsmd.getcolumncount (); i++) {System.out.print (Rsmd.getcolumnlabel (i)+ ":" + rs.getstring (i) + ""); } System.out.println (""); } }}
HSQLDB related information and usage summary