Recently, study HSQLDB, try to translate its documentation, it is posted and shared, welcome everyone and I communicate: wwccff@163.net
One is HSQLDB
HSQLDB has the following features:
L is an open source Java database
l Has standard SQL syntax and Java interface
l HSQLDB can freely use and distribute
l very simple and fast
l Three ways with memory database, independent database, and C / s database
l Use in applet
More details:
l Index can be created and automatically used
l Support transaction processing
l Allow table associations
l Integrity references and constraints
l Support Java stored procedures and functions
l Database can generate SQL scripts
l Use security mechanisms such as username, password, access.
l can be compiled by Java1.1 and Java2
HSQLDB based on HypersonicsQL is a generic purpose database, very small, and easy to install and use. Can be used in Applets, in the test, in the application system.
Since the standard SQL and JDBC interfaces are provided, HSQLDB can easily perform data conversion between other databases.
The current latest version of HSQLDB is 1.7.1, provided in the form of a compressed package, including JAR files, documents, source code, test programs, examples, etc., can be used.
Two mode of operation
HSQLDB has two modes of operation:
l In-process mode (only using applications in the same JVM can access the database)
l C / S mode (multiple computer / systems can access the same database)
Process access mode
Access mode in the process is independent mode. The independent mode here is in relation to the C / S mode (client program access database server). Here, the database and application run under the same JVM. At this time, the database is actually equivalent to the code repository called by the application. The procedures and databases communicate via a universal JDBC call, but this call is internal call and does not need to communicate via network.
In this mode, a database can only have an application access, otherwise, use the C / S mode (allowing multiple JVMs or computers to access the same database at the same time).
The URL of JDBC in this mode is as follows:
JDBC: HSQLDB: TEST
Here, Test is the database file name. Another example (under the Windows system):
JDBC: HSQLDB: C: / DB / TEST
C / S Access Mode
The database and application in this mode are not running under the same JVM process, but have their own independent processes or a separate machine. You don't need a client program to enter the server's file system. Database mode of operation in this mode does not differ from some large databases (such as SQL Server, Oracle, etc.). Can be on the Internet or intranet.
In addition to their own access protocols, HSQLDB also supports standard HTTP protocols, allowing access to the firewall or proxy server to access the database.
All Server Modes The Actual Database File Name Is Specified in The Java Command That Starts The Server. This Can Be The Dot "......... Three of the Path for the Database Name Server Mode: Server , WebServer and servlet.
l Server
The communication protocol in this mode is a HSQL proprietary protocol based on TCP / IP. Each client has a separate connection. This mode response speed is very fast. If you use a C / S mode, this service mode should be used.
The JDBC URL in this mode is:
JDBC: hsqldb: hsql: // hsqldbsrv
Here, HSQLDBSRV is a machine name. If you run multiple servers on a machine, you need to specify ports, for example: JDBC: HSQLDB: HSQL: // HSQLDBSRV: 9002, if it is a local computer, use localhost: JDBC: HSQLDB: HSQL: // localhost.
l Webserver
Sometimes, due to the presence of a firewall or proxy server, you need to use the HTTP protocol to communicate, the system provides a small and simple webserver to correspond to the database, for example:
JDBC: hsqldb: http: // WebSRV
l servlet
This mode and Webserver mode are very similar, the database is running in a servlet, while servlets can run in almost all Webserver. And compatible with the Java Servlete API (the test environment is J2DK2.1). This is directly accessed through the network. If your servlet does not directly access this database, do not use this mode.
All-in-Memory mode
The so-called full-memory access mode is all data (including indexing and recording), are saved in the main memory. This means that the size of the database is limited by the memory size (cannot exceed the size of memory). The reason for supporting this model is:
l In non-log mode, this mode is slightly faster.
l can be used under applet
l Use to store temporary data (data cache of application system) All-in-memory
The JDBC URL is as follows:
JDBC: hsqldb :..
Memory and hard disk combined access mode
In this mode, the change in the database will be written to the hard disk, which means that the table in the memory will be recreated according to their data when the database is started. Alternatively, you can create a table to save the data. When you access the database, only a small amount of records are saved in memory. You can use 'Create Cached Table' to replace 'Create Table' when you are created. Thus, the big table (the records of these tables are too larger than the memory). The index of the caching table can also be saved to the hard disk. Therefore, the size of the database may not be limited by the memory size. Entering the cache table is slower than getting data from the memory table. Starting from the 1.7.0 version, support the third mode: the data can be stored in a text file (such as a file in the CSV format). Corresponding statement: 'Create Text Table'.
The current state is saved to the disk before turning off the database. The data in the cache table is saved to a separate file. When you start HSQLDB, the database is loaded from the disk (SQL script is executed), and if the database is destroyed (such as using Ctrl C or power out), the data will not be lost. This is because when the next database is restarted, it uses the script to restore the status of the last (with the script file). Mixed binding mode
All modes can be used in one program, and the system can use these four modes in a unified time, to connect four different databases, for example:
C1 = DriverManager.getConnection ("JDBC: HSQLDB:.", "sa", "");
C2 = DriverManager.getConnection ("JDBC: HSQLDB: TEST", "SA", "");
C3 = DriverManager.getConnection ("JDBC: HSQLDB: http: // dbserver", "sa", "");
C4 = DriverManager.getConnection ("JDBC: HSQLDB: HSQL: // DBServer", "SA", "");
In this example, four connects are opened:
C1 is a memory database; C2 is open is a local database Test; C3 uses an HTTP protocol to connect to the DBServer database; C4 is also connected to the DBServer machine, but it is a faster HSQL protocol. The limit here is: only the full memory process in one process is available.
Compare
Each mode or configuration has different details and good or bad:
l transaction processing
For WebServer and Servlet mode, since the HTTP protocol is stateless, each query database creates a new connection. Each query needs to send a username and password into the database, and then create a new connection while establishing a new transaction (because the transaction is binding to the connection). You can use 'cookies', but it is not yet implemented.
l Connected and visited
Server mode allows systems and management tools (such as DatabaseManager to access databases).
l Database performance optimization factor
The memory database does not need to access the system, so it is the fastest. Other modes need to access the file system, each INSERT / UPDATE / DELETE operation is saved to the disk, so the speed is slow. If the SELECT and DELETE query the information of the cache table, the speed is almost as fast as the memory table, otherwise it is much slow (because the file system interaction with the operating system).
l Each Statement transmission time
In Server mode, each Statement requires transferring to the server via TCP / IP protocol, then returning the result to the client. The webserver and servlet modes require more time because each Statement needs to be re-established. Relative, internal mode is transmitted in one system, it is much more.
l Operate in applet
This is the full memory operation.