提交 23c4f01c authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 fe8398c0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Advanced Topics
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Advanced Topics</h1>
<a href="#resultsets">
Result Sets</a><br />
<a href="#large_objects">
Large Objects</a><br />
<a href="#linked_tables">
Linked Tables</a><br />
<a href="#transaction_isolation">
Transaction Isolation</a><br />
<a href="#clustering">
Clustering / High Availability</a><br />
<a href="#two_phase_commit">
Two Phase Commit</a><br />
<a href="#compatibility">
Compatibility</a><br />
<a href="#windows_service">
Run as Windows Service</a><br />
<a href="#odbc_driver">
ODBC Driver</a><br />
<a href="#acid">
ACID</a><br />
<a href="#using_recover_tool">
Using the Recover Tool</a><br />
<a href="#file_locking_protocols">
File Locking Protocols</a><br />
<a href="#sql_injection">
Protection against SQL Injection</a><br />
<a href="#security_protocols">
Security Protocols</a><br />
<a href="#uuid">
Universally Unique Identifiers (UUID)</a><br />
<a href="#glossary_links">
Glossary and Links</a><br />
<br /><a name="resultsets"></a>
<h2>Result Sets</h2>
<h3>Limiting the Number of Rows</h3>
Before the result is returned to the application, all rows are read by the database.
Server side cursors are not supported currently.
If only the first few rows are interesting for the application, then the
result set size should be limited to improve the performance.
This can be done using LIMIT in a query (example: SELECT * FROM TEST LIMIT 100),
or by using Statement.setMaxRows(max).
<h3>Large Result Sets and External Sorting</h3>
For result set larger than 1000 rows, the result is buffered to disk. If ORDER BY is used,
the sorting is done using an external sort algorithm. In this case, each block of rows is sorted using
quick sort, then written to disk; when reading the data, the blocks are merged together.
<br /><a name="large_objects"></a>
<h2>Large Objects</h2>
<h3>Storing and Reading Large Objects</h3>
If it is possible that the objects don't fit into memory, then the data type
CLOB (for textual data) or BLOB (for binary data) should be used.
For these data types, the objects are not fully read into memory, by using streams.
To store a BLOB, use PreparedStatement.setBinaryStream. To store a CLOB, use
PreparedStatement.setCharacterStream. To read a BLOB, use ResultSet.getBinaryStream,
and to read a CLOB, use ResultSet.getCharacterStream.
If the client/server mode is used, the BLOB and CLOB data is fully read into memory when
accessed. In this case, the size of a BLOB or CLOB is limited by the memory.
<br /><a name="linked_tables"></a>
<h2>Linked Tables</h2>
This database supports linked tables, which means tables that don't exist in the current database but
are just links to another database. To create such a link, use the CREATE LINKED TABLE statement:
<pre>
CREATE LINKED TABLE LINK('org.postgresql.Driver', 'jdbc:postgresql:test', 'sa', 'sa', 'TEST');
</pre>
It is then possible to access the table in the usual way.
There is a restriction when inserting data to this table: When inserting or updating rows into the table,
NULL values and values that are not set in the insert statement are both inserted as NULL.
This may not have the desired effect if a default value in the target table is other than NULL.
<br /><a name="transaction_isolation"></a>
<h2>Transaction Isolation</h2>
This database supports the transaction isolation level 'serializable', in which dirty reads, non-repeatable
reads and phantom reads are prohibited.
<ul>
<li><b>Dirty Reads</b><br>
Means a connection can read uncommitted changes made by another connection.
<li><b>Non-Repeatable Reads</b><br>
A connection reads a row, another connection changes a row and commits,
and the first connection re-reads the same row and gets the new result.
<li><b>Phantom Reads</b><br>
A connection reads a set of rows using a condition, another connection
inserts a row that falls in this condition and commits, then the first connection
re-reads using the same condition and gets the new row.
</ul>
<h3>Table Level Locking</h3>
The database allows multiple concurrent connections to the same database.
To make sure all connections only see consistent data, table level locking is used.
This mechanism does not allow high concurrency, but is very fast.
Shared locks and exclusive locks are supported.
Before reading from a table, the database tries to add a shared lock to the table
(this is only possible if there is no exclusive lock on the object by another connection).
If the shared lock is added successfully, the table can be read. It is allowed that
other connections also have a shared lock on the same object. If a connection wants
to write to a table (update or delete a row), an exclusive lock is required. To get the
exclusive lock, other connection must not have any locks on the object. After the
connection commits, all locks are released.
This database keeps all locks in memory.
<h3>Lock Timeout</h3>
If a connection cannot get a lock on an object, the connection waits for some amount
of time (the lock timeout). During this time, hopefully the connection holding the
lock commits and it is then possible to get the lock. If this is not possible because
the other connection does not release the lock for some time, the unsuccessful
connection will get a lock timeout exception. The lock timeout can be set individually
for each connection.
<br /><a name="clustering"></a>
<h2>Clustering / High Availability</h2>
This database supports a simple clustering / high availability mechanism. The architecture is:
two database servers run on two different computers, and on both computers is a copy of the
same database. If both servers run, each database operation is executed on both computers.
If one server fails (power, hardware or network failure), the other server can still continue to work.
From this point on, the operations will be executed only on one server until the other server
is back up.
Clustering can only be used in the server mode (the embedded mode does not support clustering).
It is possible to restore the cluster without stopping the server, however it is critical that no other
application is changing the data in the first database while the second database is restored, so
restoring the cluster is currently a manual process.
<p>
To initialize the cluster, use the following steps:
<ul>
<li>Create a database
<li>Use the CreateCluster tool to copy the database to another location and initialize the clustering.
Afterwards, you have two databases containing the same data.
<li>Start two servers (one for each copy of the database)
<li>You are now ready to connect to the databases with the client application(s)
</ul>
<h3>Using the CreateCluster Tool</h3>
To understand how clustering works, please try out the following example.
In this example, the two databases reside on the same computer, but usually, the
databases will be on different servers.
<ul>
<li>Create two directories: server1 and server2.
Each directory will simulate a directory on a computer.
<li>Start a TCP server pointing to the first directory.
You can do this using the command line:
<pre>
java org.h2.tools.Server
-tcp -tcpPort 9101
-baseDir server1
</pre>
<li>Start a second TCP server pointing to the second directory.
This will simulate a server running on a second (redundant) computer.
You can do this using the command line:
<pre>
java org.h2.tools.Server
-tcp -tcpPort 9102
-baseDir server2
</pre>
<li>Use the CreateCluster tool to initialize clustering.
This will automatically create a new, empty database if it does not exist.
Run the tool on the command line:
<pre>
java org.h2.tools.CreateCluster
-urlSource jdbc:h2:tcp://localhost:9101/test
-urlTarget jdbc:h2:tcp://localhost:9102/test
-user sa
-serverlist localhost:9101,localhost:9102
</pre>
<li>You can now connect to the databases using
an application or the H2 Console using the JDBC URL
jdbc:h2:tcp://localhost:9101,localhost:9102/test
<li>If you stop a server (by killing the process),
you will notice that the other machine continues to work,
and therefore the database is still accessible.
<li>To restore the cluster, you first need to delete the
database that failed, then restart the server that was stopped,
and re-run the CreateCluster tool.
</ul>
<br /><a name="two_phase_commit"></a>
<h2>Two Phase Commit</h2>
The two phase commit protocol is supported. 2-phase-commit works as follows:
<ul>
<li>Autocommit needs to be switched off
<li>A transaction is started, for example by inserting a row
<li>The transaction is marked 'prepared' by executing the SQL statement
<code>PREPARE COMMIT transactionName</code>
<li>The transaction can now be committed or rolled back
<li>If a problem occurs before the transaction was successfully committed or rolled back
(for example because a network problem occurred), the transaction is in the state 'in-doubt'
<li>When re-connecting to the database, the in-doubt transactions can be listed
with <code>SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT</code>
<li>Each transaction in this list must now be committed or rolled back by executing
<code>COMMIT TRANSACTION transactionName</code> or
<code>ROLLBACK TRANSACTION transactionName</code>
<li>The database needs to be closed and re-opened to apply the changes
</ul>
<br /><a name="compatibility"></a>
<h2>Compatibility</h2>
This database is (up to a certain point) compatible to other databases such as HSQLDB, MySQL and PostgreSQL.
There are certain areas where H2 is incompatible.
<h3>Transaction Commit when Autocommit is On</h3>
At this time, this database engine commits a transaction (if autocommit is switched on) just before returning the result.
For a query, this means the transaction is committed even before the application scans through the result set, and before the result set is closed.
Other database engines may commit the transaction in this case when the result set is closed.
<h3>Keywords / Reserved Words</h3>
There is a list of keywords that can't be used as identifiers (table names, column names and so on),
unless they are quoted (surrounded with double quotes). The list is currently:
<p>
CURRENT_TIMESTAMP, CURRENT_TIME, CURRENT_DATE, CROSS, DISTINCT, EXCEPT, EXISTS, FROM,
FOR, FALSE, FULL, GROUP, HAVING, INNER, INTERSECT, IS, JOIN, LIKE, MINUS, NATURAL, NOT, NULL,
ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TRUE, UNION, WHERE
<p>
Certain words of this list are keywords because they are functions that can be used without '()' for compatibility,
for example CURRENT_TIMESTAMP.
<br /><a name="windows_service"></a>
<h2>Run as Windows Service</h2>
Using a native wrapper / adapter, Java applications can be run as a Windows Service.
There are various tools available to do that. The Java Service Wrapper from Tanuki Software, Inc.
(<a href="http://wrapper.tanukisoftware.org">http://wrapper.tanukisoftware.org</a>)
is included in the installation. Batch files are provided to install, start, stop and uninstall the H2 Database Engine Service.
This service contains the TCP Server and the H2 Console web application.
The batch files are located in the directory H2/service.
<h3>Install the Service</h3>
The service needs to be registered as a Windows Service first.
To do that, double click on 1_install_service.bat.
If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear.
<h3>Start the Service</h3>
You can start the H2 Database Engine Service using the service manager of Windows,
or by double clicking on 2_start_service.bat.
Please note that the batch file does not print an error message if the service is not installed.
<h3>Connect to the H2 Console</h3>
After installing and starting the service, you can connect to the H2 Console application using a browser.
Double clicking on 3_start_browser.bat to do that. The
default port (8082) is hard coded in the batch file.
<h3>Stop the Service</h3>
To stop the service, double click on 4_stop_service.bat.
Please note that the batch file does not print an error message if the service is not installed or started.
<h3>Uninstall the Service</h3>
To uninstall the service, double click on 5_uninstall_service.bat.
If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear.
<br /><a name="odbc_driver"></a>
<h2>ODBC Driver</h2>
The ODBC driver of this database is currently not very stable and only tested superficially
with a few applications (OpenOffice 2.0, Microsoft Excel and Microsoft Access) and
data types (INT and VARCHAR), and should not be used for production applications.
Only a Windows version of the driver is available at this time.
<h3>ODBC Installation</h3>
Before the ODBC driver can be used, it needs to be installed. To do this,
double click on h2odbcSetup.exe. If you do this the first time, it will ask you to locate the
driver dll (h2odbc.dll). If you already installed it, the ODBC administration dialog will open
where you can create new or modify existing data sources.
When you create a new H2 ODBC data source, a dialog window will appear
and ask for the database settings:
<p>
<img src="odbcDataSource.png" alt="ODBC Configuration">
<h3>Log Option</h3>
The driver is able to log operations to a file.
To enable logging, the log file name must be set in the registry under the key
CURRENT_USER/Software/H2/ODBC/LogFile. This key will only be read when the
driver starts, so you need to make sure all applications that may use the driver
are closed before changing this setting.
If this registry entry is not found when the driver starts, logging is disabled.
A sample registry key file may look like this:
<pre>
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\H2\ODBC]
"LogFile"="C:\\temp\\h2odbc.txt"
</pre>
<h3>Security Considerations</h3>
Currently, the ODBC does not encrypt the password before sending it over TCP/IP to the server.
This may be a problem if an attacker can listen to the data transferred between the ODBC client
and the server, because the password is readable to the attacker.
Also, it is currently not possible to use encrypted SSL connections.
The password for a data source is stored unencrypted in the registry.
Therefore the ODBC driver should not be used where security is important.
<h3>Uninstalling</h3>
To uninstall the ODBC driver, double click on h2odbcUninstall.exe. This will uninstall the driver.
<br /><a name="acid"></a>
<h2>ACID</h2>
In the DBMS world, ACID stands for Atomicity, Consistency, Isolation, and Durability.
<ul>
<li>Atomicity: Transactions must be atomic, that means either all tasks of a transaction are performed, or none.
<li>Consistency: Only operations that comply with the defined constraints are allowed.
<li>Isolation: Transactions must be completely isolated from each other.
<li>Durability: Transaction committed to the database will not be lost.
</ul>
This database also supports these properties by default, except durability, which can only
be guaranteed by other means (battery, clustering).
<h3>Atomicity</h3>
Transactions in this database are always atomic.
<h3>Consistency</h3>
This database is always in a consistent state.
Referential integrity rules are always enforced.
<h3>Isolation</h3>
Currently, only the transaction isolation level 'serializable' is supported.
In many database, this rule is often relaxed to provide better performance,
by supporting other transaction isolation levels.
<h3>Durability</h3>
This database does not guarantee that all committed transactions survive a power failure.
If durability is required even in case of power failure, some sort of uninterruptible power supply (UPS) is required
(like using a laptop, or a battery pack). If durability is required even in case of hardware failure,
the clustering mode of this database should be used.
<p>
To achieve durability, it would be required to flush all file buffers (including system buffers) to hard disk for each commit.
In Java, there are two ways how this can be achieved:
<ul>
<li>FileDescriptor.sync(). The documentation says that this will force all system buffers to synchronize with the underlying device.
Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDesecriptor
have been written to the physical medium.
<li>FileChannel.force() (since JDK 1.4). This method is supposed to force any updates to this channel's file
to be written to the storage device that contains it.
</ul>
There is one related option, but it does not force changes to disk: RandomAccessFile(.., "rws" / "rwd"):
<ul>
<li>rws: Every update to the file's content or metadata is written synchronously to the underlying storage device.
<li>rwd: Every update to the file's content is written synchronously to the underlying storage device.
</ul>
A simple power-off test using two computers (they communicate over the network, and one the power
is switched off on one computer) shows that the data is not always persisted to the hard drive,
even when calling FileDescriptor.sync() or FileChannel.force().
The reason for this is that most hard drives do not obey the fsync() function.
For more information, see 'Your Hard Drive Lies to You' http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252&amp;tid=198&amp;tid=128).
The test was made with this database, as well as with PostgreSQL, Derby, and HSQLDB.
None of those databases was able to guarantee complete transaction durability.
<p>
The test also shows that when calling FileDescriptor.sync() or FileChannel.force() after each file operation,
only around 30 file operations per second can be made. That means, the fastest possible Java database
that calls one of those functions can reach a maximum of around 30 committed
transactions per second.
Without calling these functions, around 400000 file operations per second are possible
when using RandomAccessFile(..,"rw"), and around 2700 when using
RandomAccessFile(.., "rws"/"rwd").
<p>
That means that when using one of those functions, the performance goes down to at most
30 committed transactions per second, and even then there is no guarantee that transactions are durable.
These are the reasons that this database does not guarantee durability of transaction by default.
The database calls FileDescriptor.sync() when executing the SQL statement CHECKPOINT SYNC.
But by default, this database uses an asynchronous commit.
<h3>Running the Durability Test</h3>
To test the durability / non-durability of this and other databases, you can use the test application
in the package org.h2.test.poweroff. Two computers with network connection are required to run this test.
One computer acts as the listener, the test application is run on the other computer.
The computer with the listener application opens a TCP/IP port and listens for an incoming connection.
The second computer first connects to the listener, and then created the databases and starts inserting
records. The connection is set to 'autocommit', which means after each inserted record a commit is performed
automatically. Afterwards, the test computer notifies the listener that this record was inserted successfully.
The listener computer displays the last inserted record number every 10 seconds. Now, the power needs
to be switched off manually while the test is still running. Now you can restart the computer, and
run the application again. You will find out that in most cases, none of the databases contains all the
records that the listener computer knows about. For details, please consult the source code of the
listener and test application.
<br /><a name="using_recover_tool"></a>
<h2>Using the Recover Tool</h2>
The recover tool can be used to extract the contents of a data file, even if the database is corrupted.
At this time, it does not extract the content of the log file or large objects (CLOB or BLOB).
To run the tool, type on the command line:
<pre>
java org.h2.tools.Recover
</pre>
For each database in the current directory, a text file will be created.
This file contains raw insert statement (for the data) and data definition (DDL) statement to recreate
the schema of the database. This file cannot be executed directly, as the raw insert statements
don't have the correct table names, so the file needs to be pre-processed manually before executing.
<br /><a name="file_locking_protocols"></a>
<h2>File Locking Protocols</h2>
Whenever a database is opened, a lock file is created to signal other processes
that the database is in use. If database is closed, or if the process that opened
the database terminates, this lock file is deleted.
<p>
In special cases (if the process did not terminate normally, for example because
there was a blackout), the lock file is not deleted by the process that created it.
That means the existence of the lock file is not a safe protocol for file locking.
However, this software uses a challenge-response protocol to protect the database
files. There are two methods (algorithms) implemented to provide both security
(that is, the same database files cannot be opened by two processes at the same time)
and simplicity (that is, the lock file does not need to be deleted manually by the user).
The two methods are 'file method' and 'socket methods'.
<h3>File Locking Method 'File'</h3>
The default method for database file locking is the 'File Method'. The algorithm is:
<ul>
<li>When the lock file does not exist, it is created (using the atomic operation File.createNewFile).
Then, the process waits a little bit (20ms) and checks the file again. If the file was changed
during this time, the operation is aborted. This protects against a race condition
when a process deletes the lock file just after one create it, and a third process creates
the file again. It does not occur if there are only two writers.
<li>
If the file can be created, a random number is inserted together with the locking method
('file'). Afterwards, a watchdog thread is started that
checks regularly (every second once by default) if the file was deleted or modified by
another (challenger) thread / process. Whenever that occurs, the file is overwritten with the
old data. The watchdog thread runs with high priority so that a change to the lock file does
not get through undetected even if the system is very busy. However, the watchdog thread
does use very little resources (CPU time), because it waits most of the time. Also, the watchdog only reads from the hard disk
and does not write to it.
<li>
If the lock file exists, and it was modified in the 20 ms, the process waits for some time (up to 10 times).
If it was still changed, an exception is thrown (database is locked). This is done to eliminate race conditions with many concurrent
writers. Afterwards, the file is overwritten with a new version (challenge).
After that, the thread waits for 2 seconds.
If there is a watchdog thread protecting the file, he will overwrite the change
and this process will fail to lock the database.
However, if there is no watchdog thread, the lock file will still be as written by
this thread. In this case, the file is deleted and atomically created again.
The watchdog thread is started in this case and the file is locked.
</ul>
<p>
This algorithm is tested with over 100 concurrent threads. In some cases, when there are
many concurrent threads trying to lock the database, they block each other (meaning
the file cannot be locked by any of them) for some time. However, the file never gets
locked by two threads at the same time. However using that many concurrent threads
/ processes is not the common use case. Generally, an application should throw an error
to the user if it cannot open a database, and not try again in a (fast) loop.
<h3>File Locking Method 'Socket'</h3>
There is a second locking mechanism implemented, but disabled by default.
The algorithm is:
<ul>
<li>If the lock file does not exist, it is created.
Then a server socket is opened on a defined port, and kept open.
The port and IP address of the process that opened the database is written
into the lock file.
<li>If the lock file exists, and the lock method is 'file', then the software switches
to the 'file' method.
<li>If the lock file exists, and the lock method is 'socket', then the process
checks if the port is in use. If the original process is still running, the port is in use
and this process throws an exception (database is in use). If the original process
died (for example due to a blackout, or abnormal termination of the virtual machine),
then the port was released. The new process deletes the lock file and starts again.
</ul>
This method does not require a watchdog thread actively polling (reading) the same
file every second. The problem with this method is, if the file is stored on a network
share, two processes (running on different computers) could still open the same
database files, if they do not have a direct TCP/IP connection.
<br /><a name="sql_injection"></a>
<h2>Protection against SQL Injection</h2>
<h3>What is SQL Injection</h3>
This database engine provides a solution for the security vulnerability known as 'SQL Injection'.
Some applications build SQL statements with embedded user input such as:
<pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD='"+pwd+"'";
ResultSet rs = conn.createStatement().executeQuery(sql);
</pre>
If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded,
it is possible for a user to inject SQL functionality or statements by using specially built input
such as (in this example) this password: ' OR ''='. In this case the statement becomes:
<pre>
SELECT * FROM USERS WHERE PASSWORD='' OR ''='';
</pre>
Which is always true no matter what the password stored in the database is.
For more information about SQL Injection, see Glossary and Links.
<h3>Disabling Literals</h3>
SQL Injection is not possible if user input is not directly embedded in SQL statements.
A simple solution for the problem above is to use a PreparedStatement:
<pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD=?";
PreparedStatement prep = conn.prepareStatement(sql);
prep.setString(1, pwd);
ResultSet rs = prep.executeQuery();
</pre>
This database provides a way to enforce usage of parameters when passing user input
to the database. This is done by disabling embedded literals in SQL statements.
To do this, execute the statement:
<pre>
SET ALLOW_LITERALS NONE;
</pre>
Afterwards, SQL statements with text and number literals are not allowed any more.
That means, SQL statement of the form WHERE NAME='abc' or WHERE CustomerId=10 will fail.
It is still possible to use PreparedStatements and parameters as described above. Also, it is still possible to generate
SQL statements dynamically, and use the Statement API, as long as the SQL statements
do not include literals.
There is also a second mode where number literals are allowed: SET ALLOW_LITERALS NUMBERS.
To allow all literals, execute SET ALLOW_LITERALS ALL (this is the default setting).
Literals can only be enabled or disabled by an administrator.
<h3>Using Constants</h3>
Disabling literals also means disabling hard-coded 'constant' literals. This database supports
defining constants using the CREATE CONSTANT command. Constants can be defined only
when literals are enabled, but used even when literals are disabled. To avoid name clashes
with column names, constants can be defined in other schemas:
<pre>
CREATE SCHEMA CONST AUTHORIZATION SA;
CREATE CONSTANT CONST.ACTIVE VALUE 'Active';
CREATE CONSTANT CONST.INACTIVE VALUE 'Inactive';
SELECT * FROM USERS WHERE TYPE=CONST.ACTIVE;
</pre>
Even when literals are enabled, it is better to use constants instead
of hard-coded number or text literals in queries or views. With constants, typos are found at compile
time, the source code is easier to understand and change.
<h3>Using the ZERO() Function</h3>
It is not required to create a constant for the number 0 as there is already a built-in function ZERO():
<pre>
SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO();
</pre>
<br /><a name="security_protocols"></a>
<h2>Security Protocols</h2>
The following paragraphs document the security protocols used in this database.
These descriptions are very technical and only intended for security experts that already know
the underlying security primitives.
<h3>User Password Encryption</h3>
When a user tries to connect to a database, the combination of
user name, @, and password hashed using SHA-256, and this hash value
is transmitted to the database.
This step does not try to an attacker from re-using the value if he is able to listen to the
(unencrypted) transmission between the client and the server.
But, the passwords are never transmitted as plain text,
even when using an unencrypted connection between client and server.
That means if a user reuses the same password for different things,
this password is still protected up to some point. See also
'RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication'
for more information.
<p>
When a new database or user is created, a new cryptographically secure
random salt value is generated. The size of the salt is 64 bit.
Using the random salt reduces the risk of an attacker pre-calculating hash values
for many different (commonly used) passwords.
<p>
The combination of user-password hash value (see above) and salt is hashed
using SHA-256. The resulting value is stored in the database.
When a user tries to connect to the database, the database combines
user-password hash value with the stored salt value and calculated the
hash value. Other products use multiple iterations (hash the hash value again and again),
but this is not done in this product to reduce the risk of denial of service attacks
(where the attacker tries to connect with bogus passwords, and the server
spends a lot of time calculating the hash value for each password).
The reasoning is: if the attacker has access to the hashed passwords, he also has
access to the data in plain text, and therefore does not need the password any more.
If the data is protected by storing it on another computer and only remotely, then the iteration count is not required at all.
<h3>File Encryption</h3>
The database files can be encrypted using two different algorithms: AES-128 and
XTEA (using 32 rounds). The reasons for supporting XTEA is performance
(XTEA is about twice as fast as AES) and to have an alternative algorithm if
AES is suddenly broken.
<p>
When a user tries to connect to an encrypted database, the combination of the word
'file', @, and the file password is hashed using SHA-256. This hash value is
transmitted to the server.
<p>
When a new database file is created, a new cryptographically secure
random salt value is generated. The size of the salt is 64 bit.
The combination of the file password hash and the salt value is hashed 1024 times
using SHA-256. The reason for the iteration is to make it harder for an attacker to
calculate hash values for common passwords.
<p>
The resulting hash value is used as the key for the block cipher algorithm
(AES-128 or XTEA with 32 rounds). Then, an initialization vector (IV) key
is calculated by hashing the key again using SHA-256.
This is to make sure the IV is unknown to the attacker.
The reason for using a secret IV is to protect against watermark attacks.
<p>
Before saving a block of data (each block is 8 bytes long), the following operations are executed:
First, the IV is calculated by encrypting the block number with the IV key (using the same
block cipher algorithm). This IV is combined with the plain text using XOR. The resulting data is
encrypted using the AES-128 or XTEA algorithm.
<p>
When decrypting, the operation is done in reverse. First, the block is decrypted using the key,
and then the IV is calculated combined with the decrypted text using XOR.
<p>
Therefore, the block cipher modes of operation is CBC (Cipher-block chaining), but each chain
is only one block long. The advantage over the ECB (Electronic codebook) mode is that patterns
in the data are not revealed, and the advantage over multi block CBC is that flipped cipher text bits
are not propagated to flipped plaintext bits in the next block.
<h3>SSL/TLS Connections</h3>
Remote SSL/TLS connections are supported using the Java Secure Socket Extension
(SSLServerSocket / SSLSocket). By default, anonymous SSL is enabled.
The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code>.
<h3>HTTPS Connections</h3>
The web server supports HTTP and HTTPS connections using SSLServerSocket.
There is a default self-certified certificate to support an easy starting point, but
custom certificates are supported as well.
<br /><a name="uuid"></a>
<h2>Universally Unique Identifiers (UUID)</h2>
This database supports the UUIDs, and function to create new value using
a cryptographically strong pseudo random number generator.
With random UUIDs, the chance of two having the same value can be calculated
using the probability theory. See also 'Birthday Paradox'.
Standarized randomly generated UUIDs have 122 random bits.
4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz).
This database supports generating such UUIDs using the built-in function RANDOM_UUID().
Here is a small program to estimate the proability of having two identical UUIDs
after generating a number of values:
<pre>
double x = Math.pow(2, 122);
for(int i=35; i<62; i++) {
double n = Math.pow(2, i);
double p = 1 - Math.exp(-(n*n)/(2*x));
String ps = String.valueOf(1+p).substring(1);
System.out.println("2^"+i+"="+(1L&lt;&lt;i)+" probability: 0"+ps);
}
</pre>
Some values are:
<pre>
2^36=68'719'476'736 probability: 0.000'000'000'000'000'4
2^41=2'199'023'255'552 probability: 0.000'000'000'000'4
2^46=70'368'744'177'664 probability: 0.000'000'000'4
</pre>
One's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion,
that means the probability is about 0.000'000'000'06.
<br /><a name="glossary_links"></a>
<h2>Glossary and Links</h2>
<table><tr><th>Term</th><th>Description</th></tr>
<tr>
<td>AES-128</td>
<td>
A block encryption algorithm. See also:
<a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">Wikipedia: AES</a>
</td>
</tr>
<tr>
<td>Birthday Paradox</td>
<td>
Describes the higher than expected probability that two persons in a room have the same birthday.
Also valid for randomly generated UUIDs. See also:
<a href="http://en.wikipedia.org/wiki/Birthday_paradox">Wikipedia: Birthday Paradox</a>
</td>
</tr>
<tr>
<td>Digest</td>
<td>
Protocol to protect a password (but not to protect data). See also:
<a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617: HTTP Digest Access Authentication</a>
</td>
</tr>
<tr>
<td>GCJ</td>
<td>
GNU Compiler for Java.
<a href="http://gcc.gnu.org/java/">http://gcc.gnu.org/java/</a> and
<a href="http://javacompiler.mtsystems.ch/">http://javacompiler.mtsystems.ch/</a>
</td>
</tr>
<tr>
<td>HTTPS</td>
<td>
A protocol to provide security to HTTP connections. See also:
<a href="http://www.ietf.org/rfc/rfc2818.txt">RFC 2818: HTTP Over TLS</a>
</td>
</tr>
<tr>
<td>Modes of Operation</td>
<td>
<a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation">Wikipedia: Block cipher modes of operation</a>
</td>
</tr>
<tr>
<td>Salt</td>
<td>
Random number to increase the security of passwords.
See also:
<a href="http://en.wikipedia.org/wiki/Key_derivation_function">Wikipedia: Key derivation function</a>
</td>
</tr>
<tr>
<td>SHA-256</td>
<td>
A cryptographic one-way hash function.
See also:
<a href="http://en.wikipedia.org/wiki/SHA_family">Wikipedia: SHA hash functions</a>
</td>
</tr>
<tr>
<td>SQL Injection</td>
<td>
A security vulnerability where an application generates SQL statements with embedded user input.
See also:
<a href="http://en.wikipedia.org/wiki/SQL_injection">Wikipedia: SQL Injection</a>
</td>
</tr>
<tr>
<td>Watermark Attack</td>
<td>
Security problem of certain encryption programs where the existence of certain
data can be proven without decrypting.
For more information, search in the internet for 'watermark attack cryptoloop'
</td>
</tr>
<tr>
<td>SSL/TLS</td>
<td>
Secure Sockets Layer / Transport Layer Security.
See also:
<a href="http://java.sun.com/products/jsse/">Java Secure Socket Extension (JSSE)</a>
</td>
</tr>
<tr>
<td>XTEA</td>
<td>
A block encryption algorithm.
See also:
<a href="http://en.wikipedia.org/wiki/XTEA">Wikipedia: XTEA</a>
</td>
</tr>
</table>
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Build
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Build</h1>
<a href="#portability">
Portability</a><br />
<a href="#environment">
Environment</a><br />
<a href="#building">
Building the Software</a><br />
<a href="#maven2">
Using Maven 2</a><br />
<br /><a name="portability"></a>
<h2>Portability</h2>
This database is written in Java and therefore works on many platforms.
It is also possible to compile it to a native executable using GCJ.
<br /><a name="environment"></a>
<h2>Environment</h2>
To build the database executables, the following software stack was used.
In most cases, newer version or compatible software works too, but this was not tested.
<ul>
<li>Windows XP
<li>Sun JDK Version 1.4
<li>Apache Ant Version 1.6.5
<li>Mozilla Firefox 1.5
<li>Eclipse Version 3.2.1
<li>YourKit Java Profiler
</ul>
<br /><a name="building"></a>
<h2>Building the Software</h2>
On the command line, go to the directory src and execute the following command:
<pre>
ant -projecthelp
</pre>
You will get a list of targets. If you want to build the jar files, execute:
<pre>
ant jar
</pre>
To create a jar file with the JDBC API and the classes required to connect to a server only,
use the target jarClient:
<pre>
ant jarClient
</pre>
The other targets may be used as well.
<br /><a name="maven2"></a>
<h2>Using Maven 2</h2>
To build and upload the H2 .jar file to the local Maven 2 repository, execute the following command:
<pre>
ant mavenUploadLocal
</pre>
Afterwards, you can include the database in your Maven 2 project as a dependency:
<pre>
&lt;dependency&gt;
&lt;groupId&gt;org.h2database&lt;/groupId&gt;
&lt;artifactId&gt;h2&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></td></tr></table></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Data Types
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Data Types</h1>
<c:forEach var="item" items="dataTypes">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<c:forEach var="item" items="dataTypes">
<br>
<a name="sql${item.id}"></a><h3>${item.topic}</h3>
<pre>
${item.syntax}
</pre>
${item.text}
<p>
<b>Example:</b><br>
${item.example}
<br>
</c:forEach>
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Frequently Asked Questions
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Frequently Asked Questions</h1>
<h3>Are there any known bugs? When is the next release?</h3>
Usually, bugs get fixes as they are found. There is a release every few weeks.
The next release is planned for
2006-12-18.
Here is the list of known and confirmed issues as of
2006-12-03:
<ul>
<li>There are some browser issues with the autocomplete feature. Firefox should work however.
<li>Some problems have been found with right outer join. Internally, it is converted to left outer join, which
does not always produce the correct results when used in combination with other joins.
</ul>
<h3>Is this Database Engine Open Source?</h3>
Yes. It is free to use and distribute, and the source code is included.
See also under license.
<h3>Is the GCJ version stable? Faster?</h3>
The GCJ version is not as stable as the Java version.
When running the regression test with the GCJ version, sometimes the application just stops
at what seems to be a random point without error message.
Currently, the GCJ version is also slower than when using the Sun VM.
However, the startup of the GCJ version is faster than when using a VM.
<h3>Is it Reliable?</h3>
That is not easy to say. It is still a quite new product. A lot of tests have been written,
and the code coverage of these tests is very high. Randomized stress tests
are run regularly. But as this is a relatively new product, there are probably
some problems that have not yet been found.
Areas that are not completely tested:
<ul>
<li>Platforms other than Windows XP and the Sun JVM 1.4
<li>Data types BLOBs / CLOBs, VARCHAR_IGNORECASE, OTHER
<li>Cluster mode, 2-Phase Commit, Savepoints
<li>Server mode (well tested, but not as well as Embedded mode)
<li>Multi-Threading and using multiple connections
<li>Updatable result sets
<li>Referential integrity and check constraints, Triggers
<li>ALTER TABLE statements, Views, Linked Tables, Schema, UNION
<li>Not all built-in functions are completely tested
<li>The Optimizer may not always select the best plan
<li>24/7 operation and large databases (500 MB and up)
<li>Wide indexes with large VARCHAR or VARBINARY columns and / or with a lot of columns
</ul>
Areas considered Experimental:
<ul>
<li>ODBC driver and the GCJ native version on Windows
<li>Linear Hash Index
<li>Compatibility modes for other databases (only some features are implemented)
</ul>
<h3>How to Create a New Database?</h3>
By default, a new database is automatically created if it does not yet exist.
<h3>How to Connect to a Database?</h3>
The database driver is <code>org.h2.Driver</code>,
and the database URL starts with <code>jdbc:h2:</code>.
To connect to a database using JDBC, use the following code:
<pre>
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
</pre>
<h3>Where are the Database Files Stored?</h3>
If the base directory is not set, the database files are stored in the directory where the application is started
(the current working directory). When using the H2 Console application from the start menu, this is [Installation Directory]/bin.
The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL
jdbc:h2:file:data/sample, the database is stored in the directory data (relative to the current working directory).
The directory must exist. It is also possible to use the fully qualified directory (and for Windows, drive) name.
Example: jdbc:h2:file:C:/data/test
<h3>What is the Size Limit of a Database?</h3>
The theoretical limit is currently 256 GB for the data. This number is excluding BLOB and CLOB data:
Every CLOB or BLOB can be up to 256 GB as well. The size limit of the index data is 256 GB as well.
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Features
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Features</h1>
<a href="#feature_list">
Feature List</a><br />
<a href="#comparison">
Comparison to Other Database Engines</a><br />
<a href="#products_work_with">
Products that Work with H2</a><br />
<a href="#why_java">
Why Java</a><br />
<a href="#connection_modes">
Connection Modes</a><br />
<a href="#database_url">
Database URL Overview</a><br />
<a href="#file_encryption">
Connecting to a Database with File Encryption</a><br />
<a href="#database_file_locking">
Database File Locking</a><br />
<a href="#database_only_if_exists">
Opening a Database Only if it Already Exists</a><br />
<a href="#closing_the_database">
Closing the Database</a><br />
<a href="#log_index_changes">
Log Index Changes</a><br />
<a href="#multiple_connections">
Multiple Connections</a><br />
<a href="#database_file_layout">
Database File Layout</a><br />
<a href="#logging_recovery">
Logging and Recovery</a><br />
<a href="#compatibility_modes">
Compatibility Modes</a><br />
<a href="#trace_options">
Using the Trace Options</a><br />
<a href="#read_only">
Read Only Databases</a><br />
<a href="#storage_formats">
Binary and Text Storage Formats</a><br />
<a href="#low_disk_space">
Graceful Handling of Low Disk Space Situations</a><br />
<a href="#computed_columns">
Computed Columns / Function Based Index</a><br />
<a href="#multi_dimensional">
Multi-Dimensional Indexes</a><br />
<a href="#passwords">
Using Passwords</a><br />
<a href="#user_defined_functions">
User Defined Functions and Stored Procedures</a><br />
<a href="#triggers">
Triggers</a><br />
<a href="#compacting">
Compacting a Database</a><br />
<a href="#cache_settings">
Cache Settings</a><br />
<br /><a name="feature_list"></a>
<h2>Feature List</h2>
<h3>Main Features</h3>
<ul>
<li>Very fast database engine
<li>Free, with source code
<li>Written in Java
<li>Supports standard SQL, JDBC API
<li>Embedded and Server mode, Clustering support
<li>Strong security features
<li>Experimental native version (GCJ) and ODBC drivers
</ul>
<h3>Additional Features</h3>
<ul>
<li>Disk based or in-memory databases and tables, read-only database support, temporary tables
<li>Transaction support (serializable transaction isolation), 2-phase-commit
<li>Multiple connections, table level locking
<li>Cost based optimizer, using a genetic algorithm for complex queries, zero-administration
<li>Scrollable and updatable result set support, large result set, external result sorting, functions can return a result set
<li>Encrypted database (AES or XTEA), SHA-256 password encryption, encryption functions, SSL
</ul>
<h3>SQL Support</h3>
<ul>
<li>Compatibility modes for HSQLDB, MySQL and PostgreSQL
<li>Support for multiple schemas, information schema
<li>Referential integrity / foreign key constraints with cascade, check constraints
<li>Inner and outer joins, subqueries, read only views and inline views
<li>Triggers and Java functions / stored procedures
<li>Many built-in functions, including XML and lossless data compression
<li>Wide range of data types including large objects (BLOB/CLOB)
<li>Sequence and autoincrement columns, computed columns (can be used for function based indexes)
<li>ORDER BY, GROUP BY, HAVING, UNION, LIMIT, TOP
<li>Collation support, Users, Roles
</ul>
<h3>Security Features</h3>
<ul>
<li>User password authenticated uses SHA-256 and salt
<li>User passwords are never transmitted in plain text over the network (even when using insecure connections)
<li>All database files (including script files that can be used to backup data) can be encrypted using AES-256 and XTEA encryption algorithms
<li>The remote JDBC driver supports TCP/IP connections over SSL/TLS
<li>The built-in web server supports connections over SSL/TLS
<li>Passwords can be sent to the database using char arrays instead of Strings
<li>Includes a solution for the SQL injection problem
</ul>
<h3>Other Features and Tools</h3>
<ul>
<li>Small footprint (smaller than 1 MB), low memory requirements
<li>Multiple index types (b-tree, tree, hash, linear hash)
<li>Support for multi-dimensional indexes
<li>CSV file support
<li>Support for linked tables, and a built-in virtual 'range' table
<li>EXPLAIN PLAN support, sophisticated trace options
<li>Database closing can be delayed or disabled to improve the performance
<li>Web-based Console application (English, German, partially French and Spanish) with autocomplete
<li>The database can generate SQL script files
<li>Contains a recovery tool that can dump the contents of the data file
<li>Automatic re-compilation of prepared statements
<li>Uses a small number of database files, binary and text storage formats, graceful handling of low disk space situations
<li>Uses a checksum for each record and log entry for data integrity
<li>Well tested (high code coverage, randomized stress tests)
</ul>
<br /><a name="comparison"></a>
<h2>Comparison to Other Database Engines</h2>
<table><tr>
<th>Feature</th>
<th>H2</th>
<th>HSQLDB</th>
<th>Derby</th>
<th>Daffodil</th>
<th>MySQL</th>
<th>PostgreSQL</th>
</tr><tr>
<td>Embedded Mode (Java)</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareN">No</td>
</tr><tr>
<td>Performance (Embedded)</td>
<td class="compareY">Fast</td>
<td class="compareY">Fast</td>
<td class="compareN">Slow</td>
<td class="compareN">Slow</td>
<td class="compareN">N/A</td>
<td class="compareN">N/A</td>
</tr><tr>
<td>Performance (Server)</td>
<td class="compareY">Fast</td>
<td class="compareY">Fast</td>
<td class="compareN">Slow</td>
<td class="compareN">Slow</td>
<td class="compareN">Slow</td>
<td class="compareN">Slow</td>
</tr><tr>
<td>Transaction Isolation</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
</tr><tr>
<td>Cost Based Optimizer</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
</tr><tr>
<td>Clustering</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareN">No</td>
<td class="compareN">No</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
</tr><tr>
<td>Encrypted Database</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareY">Yes</td>
<td class="compareN">No</td>
<td class="compareN">No</td>
<td class="compareN">No</td>
</tr><tr>
<td>Files per Database</td>
<td class="compareY">Few</td>
<td class="compareY">Few</td>
<td class="compareN">Many</td>
<td class="compareY">Few</td>
<td class="compareN">Many</td>
<td class="compareN">Many</td>
</tr><tr>
<td>Footprint (jar/dll size)</td>
<td class="compareY">~ 1 MB</td>
<td class="compareY">~ 600 KB</td>
<td class="compareY">~ 2 MB</td>
<td class="compareY">~ 3 MB</td>
<td class="compareN">~ 4 MB</td>
<td class="compareN">~ 6 MB</td>
</tr>
</table>
<br /><a name="products_work_with"></a>
<h2>Products that Work with H2</h2>
<table>
<tr><th>Product</th><th>Description</th></tr>
<tr>
<td><a href="http://hibernate.org">Hibernate</a></td>
<td>Relational Persistence for Idiomatic Java (O-R Mapping Tool)</td>
</tr><tr>
<td><a href="http://www.jpox.org">JPOX</a></td>
<td>Java Persistent Objects</td>
</tr><tr>
<td><a href="http://www.jenkov.com/mrpersister/introduction.tmpl">Mr. Persister</a></td>
<td>Simple, small and fast object relational mapping</td>
</tr><tr>
<td><a href="http://luntbuild.javaforge.com">Luntbuild</a></td>
<td>Build automation and management tool</td>
</tr><tr>
<td><a href="http://squirrelsql.org">SQuirreL SQL Client</a></td>
<td>Graphical tool to view the structure of a database, browse the data, issue SQL commands etc.</td>
</tr><tr>
<td><a href="http://dbcopyplugin.sf.net">SQuirreL DB Copy Plugin</a></td>
<td>Tool to copy data from one database to another.</td>
</tr><tr>
<td><a href="http://www.minq.se/products/dbvis">DbVisualizer</a></td>
<td>Database tool.</td>
</tr><tr>
<td><a href="http://www.polepos.org">PolePosition</a></td>
<td>Open source database benchmark.</td>
</tr><tr>
<td><a href="http://bmarks-portlet.sourceforge.net">Bookmarks Portlet</a></td>
<td>JSR168 compliant bookmarks management portlet application.</td>
</tr><tr>
<td><a href="http://www.shellbook.com">Shellbook</a></td>
<td>Desktop Publishing application.</td>
</tr><tr>
<td><a href="http://www.goldenstudios.or.id">Golden T Studios</a></td>
<td>Fun-to-play games with a simple interface.</td>
</tr><tr>
<td><a href="http://www.webofweb.net">Web of Web</a></td>
<td>Collaborative and realtime interactive media platform for the web.</td>
</tr><tr>
<td><a href="http://jamwiki.org">JAMWiki</a></td>
<td>Java-based Wiki engine.</td>
</tr><tr>
<td><a href="http://executequery.org">Execute Query</a></td>
<td>Database utility written in Java.</td>
</tr><tr>
<td><a href="http://sql-workbench.net">SQL Workbench/J</a></td>
<td>Free DBMS-independent SQL Tool.</td>
</tr>
</table>
<br /><a name="why_java"></a>
<h2>Why Java</h2>
A few reasons using a Java database are:
<ul>
<li>Very simple to integrate in Java applications
<li>Support for many different platforms
<li>More secure than native applications (no buffer overflows)
<li>User defined functions (or triggers) run very fast
<li>Unicode support
</ul>
Some people think that Java is still too slow for low level operations,
but this is not the case (not any more). In general, the code can be written a lot faster
than using C or C++. Like that, it is possible to concentrate on improving the algorithms
(that make the application faster) rather than porting the code and dealing with low
level stuff (such as memory management or dealing with threads).
Garbage collection is now probably faster than manual memory management.
<p>
A lot of features are already built in (for example Unicode, network libraries).
It is very easy to write secure code because buffer overflows and such
problems can be detected very easily. Some features such as the reflection
mechanism can be used for randomized testing.
<p>
Java is also future proof: A lot of companies support Java, and the
open source support for Java is getting better as well (see GCJ).
<p>
This software does not rely on many Java libraries or other software, to
increase the portability and ease of use, and for performance reasons. For example,
the encryption algorithms and many library functions are implemented in the database
instead of using the existing libraries. Libraries that are not available in open source
Java implementations (such as Swing) are not used or only used for specific features
(such as the SysTray library).
<br /><a name="connection_modes"></a>
<h2>Connection Modes</h2>
The following connection modes are supported:
<ul>
<li>Local connections using JDBC (embedded)
<li>Remote connections using JDBC over TCP/IP (client/server)
<li>Remote connections using ODBC over TCP/IP (client/server)
<li>In-Memory databases (private and shared)
</ul>
<br /><a name="database_url"></a>
<h2>Database URL Overview</h2>
This database does support multiple connection modes and features when connecting to a database.
This is achieved using different database URLs. The settings in the URLs are not case sensitive.
<table><tr><th>Topic</th><th>URL Format and Examples</th></tr>
<tr>
<td>Embedded (local) connection</td>
<td>
jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;<br>
jdbc:h2:test<br>
jdbc:h2:file:/data/sample<br>
jdbc:h2:file:C:/data/sample (Windows only)<br>
</td>
</tr>
<tr>
<td>In-Memory (private)</td>
<td>jdbc:h2:mem:</td>
</tr>
<tr>
<td>In-Memory (named)</td>
<td>
jdbc:h2:mem:&lt;databaseName&gt;<br>
jdbc:h2:mem:imdb1
</td>
</tr>
<tr>
<td>Remote using TCP/IP</td>
<td>
jdbc:h2:tcp://&lt;server&gt;[&lt;port&gt;]/&lt;databaseName&gt;<br>
jdbc:h2:tcp://localhost/test<br>
jdbc:h2:tcp://dbserv:8084/sample
</td>
</tr>
<tr>
<td>Remote using SSL/TLS</td>
<td>
jdbc:h2:ssl://&lt;server&gt;[&lt;port&gt;]/&lt;databaseName&gt;<br>
jdbc:h2:ssl://secureserv:8085/sample;
</td>
</tr>
<tr>
<td>Using Encrypted Files</td>
<td>
jdbc:h2:&lt;url&gt;;CIPHER=[AES][XTEA]<br>
jdbc:h2:ssl://secureserv/testdb;CIPHER=AES<br>
jdbc:h2:file:secure;CIPHER=XTEA<br>
</td>
</tr>
<tr>
<td>File Locking Methods</td>
<td>
jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET}<br>
jdbc:h2:file:quickAndDirty;FILE_LOCK=NO<br>
jdbc:h2:file:private;CIPHER=XTEA;FILE_LOCK=SOCKET<br>
</td>
</tr>
<tr>
<td>Only Open if it Already Exists</td>
<td>
jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE<br>
jdbc:h2:file:sample;IFEXISTS=TRUE<br>
</td>
</tr>
<tr>
<td>Don't Close the Database when the VM Exits</td>
<td>
jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE
</td>
</tr>
<tr>
<td>User Name and/or Password</td>
<td>
jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;]<br>
jdbc:h2:file:sample;USER=sa;PASSWORD=123<br>
</td>
</tr>
<tr>
<td>Log Index Changes</td>
<td>
jdbc:h2:&lt;url&gt;;LOG=2<br>
jdbc:h2:file:sample;LOG=2<br>
</td>
</tr>
<tr>
<td>Debug Trace Settings</td>
<td>
jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt;<br>
jdbc:h2:file:sample;TRACE_LEVEL_FILE=3<br>
</td>
</tr>
<tr>
<td>Ignore Unknown Settings</td>
<td>
jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE<br>
</td>
</tr>
<tr>
<td>Changing Other Settings</td>
<td>
jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...]<br>
jdbc:h2:file:sample;TRACE_LEVEL_SYSTEM_OUT=3<br>
</td>
</tr>
</table>
<h3>Connecting to an Embedded (Local) Database</h3>
The database URL for connecting to a local database is <code>jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code>.
The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working
directory is used as a starting point. The case sensitivity of the path and database name depend on the
operating system, however it is suggested to use lowercase letters only.
<h3>Memory-Only Databases</h3>
For certain use cases (for example: rapid prototyping, testing, high performance
operations, read-only databases), it may not be required to persist (changes to) the data at all.
This database supports the memory-only mode, where the data is not persisted.
<p>
In some cases, only one connection to a memory-only database is required.
This means the database to be opened is private. In this case, the database URL is
<code>jdbc:h2:mem:</code> Opening two connections within the same virtual machine
means opening two different (private) databases.
<p>
Some times multiple connections to the same memory-only database are required.
In this case, the database URL must include a name. Example: <code>jdbc:h2:mem:db1</code>
<p>
It is also possible to open a memory-only database remotely using TCP/IP or SSL/TLS.
An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code>
(using private database remotely is also possible).
<br /><a name="file_encryption"></a>
<h2>Connecting to a Database with File Encryption</h2>
To use file encryption, it is required to specify the encryption algorithm (the 'cipher')
and the file password. The algorithm needs to be specified using the connection parameter.
Two algorithms are supported: XTEA and AES. The file password is specified in the password field,
before the user password. A single space needs to be added between the file password
and the user password; the file password itself may not contain spaces. File passwords
(as well as user passwords) are case sensitive. Here is an example to connect to a password
encrypted database:
<pre>
Class.forName("org.h2.Driver");
String url = "jdbc:h2:test;CIPHER=AES";
String user = "sa";
String pwds = "filepwd userpwd";
conn = DriverManager.
getConnection(url, user, pwds);
</pre>
<br /><a name="database_file_locking"></a>
<h2>Database File Locking</h2>
Whenever a database is opened, a lock file is created to signal other processes
that the database is in use. If database is closed, or if the process that opened
the database terminates, this lock file is deleted.
<p>
The following file locking methods are implemented:
<ul>
<li>The default method is 'file' and uses a watchdog thread to
protect the database file. The watchdog reads the lock file each second.
<li>The second method is 'socket' and opens a server socket. The socket method does
not require reading the lock file every second. The socket method should only be used
if the database files are only accessed by the one (and always the same) computer.
<li>It is also possible to open the database without file locking;
in this case it is up to the application to protect the database files.
</ul>
To open the database with a different file locking method, use the parameter 'FILE_LOCK'.
The following code opens the database with the 'socket' locking method:
<pre>
String url = "jdbc:h2:test;FILE_LOCK=SOCKET";
</pre>
The following code forces the database to not create a lock file at all. Please note that
this is unsafe as another process is able to open the same database, possibly leading to
data corruption:
<pre>
String url = "jdbc:h2:test;FILE_LOCK=NO";
</pre>
For more information about the algorithms please see in Advanced Topics under
File Locking Protocol.
<br /><a name="database_only_if_exists"></a>
<h2>Opening a Database Only if it Already Exists</h2>
By default, when an application calls <code>DriverManager.getConnection(url,...)</code>
and the database specified in the URL does not yet exist, a new (empty) database is created.
In some situations, it is better to restrict creating new database, and only open
the database if it already exists. This can be done by adding <code>;ifexists=true</code>
to the URL. In this case, if the database does not already exist, an exception is thrown when
trying to connect. The connection only succeeds when the database already exists.
The complete URL may look like this:
<pre>
String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE";
</pre>
<br /><a name="closing_the_database"></a>
<h2>Closing the Database</h2>
<h3>Delayed Database Closing</h3>
Usually, the database is closed when the last connection to it is closed. In some situations
this slows down the application, for example when it is not possible leave the connection open.
The automatic closing of the database can be delayed or disabled with the SQL statement
SET DB_CLOSE_DELAY &lt;seconds&gt;. The seconds specifies the number of seconds to keep
a database open after the last connection to it was closed. For example the following statement
will keep the database open for 10 seconds:
<pre>
SET DB_CLOSE_DELAY 10
</pre>
The value -1 means the database is never closed automatically.
The value 0 is the default and means the database is closed when the last connection is closed.
This setting is persistent and can be set by an administrator only.
It is possible to set the value in the database URL: <code>jdbc:h2:test;DB_CLOSE_DELAY=10</code>.
<h3>Don't Close the Database when the VM Exits</h3>
By default, a database is closed when the last connection is closed. However, if it is never closed,
the database is closed when the virtual machine exits normally. This is done using a shutdown hook.
In some situations, the database should not be closed in this case, for example because the
database is still used at virtual machine shutdown (to store the shutdown process in the database for example).
In this case, the automatic closing of the database can be disabled.
This can be done in the database URL. The first connection (the one that is opening the database) needs to
set the option in the database URL (it is not possible to change the setting afterwards).
The database URL to disable database closing on exit is:
<pre>
String url = "jdbc:h2:test;DB_CLOSE_ON_EXIT=FALSE";
</pre>
<br /><a name="log_index_changes"></a>
<h2>Log Index Changes</h2>
Usually, changes to the index file are not logged for performance.
If the index file is corrupt or missing when opening a database, it is re-created from the data.
The index file can get corrupt when the database is not shut down correctly,
because of power failure or abnormal program termination.
In some situations, for example when using very large databases (over a few hundred MB),
re-creating the index file takes very long.
In these situations it may be better to log changes to the index file,
so that recovery from a corrupted index file is fast.
To enable log index changes, add LOG=2 to the URL, as in jdbc:h2:test;LOG=2
This setting should be specified when connecting.
The update performance of the database will be reduced when using this option.
<h3>Ignore Unknown Settings</h3>
Some applications (for example OpenOffice.org Base) pass some additional parameters
when connecting to the database. Why those parameters are passed is unknown.
The parameters PREFERDOSLIKELINEENDS and IGNOREDRIVERPRIVILEGES are such examples,
they are simply ignored to improve the compatibility with OpenOffice.org. If an application
passes other parameters when connecting to the database, usually the database throws an exception
saying the parameter is not supported. It is possible to ignored such parameters by adding
;IGNORE_UNKNOWN_SETTINGS=TRUE to the database URL.
<h3>Changing Other Settings when Opening a Connection</h3>
In addition to the settings already described (cipher, file_lock, ifexists, user, password),
other database settings can be passed in the database URL.
Adding <code>setting=value</code> at the end of an URL is the
same as executing the statement <code>SET setting value</code> just after
connecting. For a list of settings supported by this database please see the
SQL grammar documentation.
<br /><a name="multiple_connections"></a>
<h2>Multiple Connections</h2>
<h3>Opening Multiple Databases at the Same Time</h3>
An application can open multiple databases at the same time, including multiple
connections to the same database. The number of open database is only limited by the memory available.
<h3>Multiple Connections to the Same Database: Client/Server</h3>
If you want to access the same database at the same time from different processes or computers,
you need to use the client / server mode. In this case, one process acts as the server, and the
other processes (that could reside on other computers as well) connect to the server via TCP/IP
(or SSL/TLS over TCP/IP for improved security).
<h3>Multithreading Support</h3>
This database is multithreading-safe. That means, if an application is multi-threaded, it does not need
to worry about synchronizing the access to the database. Internally, most requests to the same database
are synchronized. That means an application can use multiple threads all accessing the same database
at the same time, however if one thread executes a long running query, the other threads
need to wait.
<h3>Locking, Lock-Timeout, Deadlocks</h3>
The database uses table level locks to give each connection a consistent state of the data.
There are two kinds of locks: read locks (shared locks) and write locks (exclusive locks).
If a connection wants to reads from a table, and there is no write lock on the table,
then a read lock is added to the table. If there is a write lock, then this connection waits
for the other connection to release the lock. If connection cannot get a lock for a specified time,
then a lock timeout exception is thrown.
<p>
Usually, SELECT statement will generate read locks. This includes subqueries.
Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data,
using the statement SELECT ... FOR UPDATE.
The statements COMMIT and ROLLBACK releases all open locks.
The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks.
The locks are also released when the autocommit mode changes, and for connections with
autocommit set to true (this is the default), locks are released after each statement.
Here is an overview on what statements generate what type of lock:
<table><tr><th>Type of Lock</th><th>SQL Statement</th></tr>
<tr>
<td>
Read
</td>
<td>
SELECT * FROM TEST<br>
CALL SELECT MAX(ID) FROM TEST<br>
SCRIPT
</td>
</tr>
<tr>
<td>
Write
</td>
<td>
SELECT * FROM TEST WHERE 1=0 FOR UPDATE
</td>
</tr>
<tr>
<td>
Write
</td>
<td>
INSERT INTO TEST VALUES(1, 'Hello')<br>
INSERT INTO TEST SELECT * FROM TEST<br>
UPDATE TEST SET NAME='Hi'<br>
DELETE FROM TEST
</td>
</tr>
<tr>
<td>
Write
</td>
<td>
ALTER TABLE TEST ...<br>
CREATE INDEX ... ON TEST ...<br>
DROP INDEX ...
</td>
</tr>
</table>
<p>
The number of seconds until a lock timeout exception is thrown can be
set separately for each connection using the SQL command SET LOCK_TIMEOUT &lt;milliseconds&gt;.
The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command
SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
<br /><a name="database_file_layout"></a>
<h2>Database File Layout</h2>
There are a number of files created for persistent databases. Other than some databases,
not every table and/or index is stored in its own file. Instead, usually only the following files are created:
A data file, an index file, a log file, and a database lock file (exists only while the database is in use).
In addition to that, a file is created for each large object (CLOB/BLOB), a file for each linear index,
and temporary files for large result sets. Then the command SCRIPT can create script files.
If the database trace option is enabled, trace files are created.
The following files can be created by the database:
<table><tr><th>File Name</th><th>Description</th><th>Number of Files</th></tr>
<tr><td>
test.data.db
</td><td>
Data file<br>
Contains the data for all tables<br>
Format: &lt;database&gt;.data.db
</td><td>
1 per database
</td></tr>
<tr><td>
test.index.db
</td><td>
Index file<br>
Contains the data for all (btree) indexes<br>
Format: &lt;database&gt;.index.db
</td><td>
1 per database
</td></tr>
<tr><td>
test.0.log.db
</td><td>
Log file<br>
The log file is used for recovery<br>
Format: &lt;database&gt;.&lt;id&gt;.log.db
</td><td>
0 or more per database
</td></tr>
<tr><td>
test.lock.db
</td><td>
Database lock file<br>
Exists only if the database is open<br>
Format: &lt;database&gt;.lock.db
</td><td>
1 per database
</td></tr>
<tr><td>
test.trace.db
</td><td>
Trace file<br>
Contains trace information<br>
Format: &lt;database&gt;.trace.db<br>
If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
</td><td>
1 per database
</td></tr>
<tr><td>
test.14.15.lob.db
</td><td>
Large object<br>
Contains the data for BLOB or CLOB<br>
Format: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db
</td><td>
1 per object
</td></tr>
<tr><td>
test.123.temp.db
</td><td>
Temporary file<br>
Contains a temporary blob or a large result set<br>
Format: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db
</td><td>
1 per object
</td></tr>
<tr><td>
test.7.hash.db
</td><td>
Hash index file<br>
Contains the data for a linear hash index<br>
Format: &lt;database&gt;.&lt;object id&gt;.hash.db
</td><td>
1 per linear hash index
</td></tr>
</table>
<h3>Moving and Renaming Database Files</h3>
Database name and location are not stored inside the database names.
<p>
While a database is closed, the files can be moved to another directory, and they can be renamed
as well (as long as all files start with the same name).
<p>
As there is no platform specific data in the files, they can be moved to other operating systems
without problems.
<h3>Backup</h3>
When the database is closed, it is possible to backup the database files. Please note that index
files do not need to be backed up, because they contain redundant data, and will be recreated
automatically if they don't exist.
<p>
To backup data while the database is running, the SQL command SCRIPT can be used.
<br /><a name="logging_recovery"></a>
<h2>Logging and Recovery</h2>
Whenever data is modified in the database and those changes are committed, the changes are logged
to disk (except for in-memory objects). The changes to the data file itself are usually written
later on, to optimize disk access. If there is a power failure, the data and index files are not up-to-date.
But because the changes are in the log file, the next time the database is opened, the changes that are
in the log file are re-applied automatically.
<p>
Please note that index file updates are not logged by default. If the database is opened and recovery is required,
the index file is rebuilt from scratch.
<p>
There is usually only one log file per database. This file grows until the database is closed successfully,
and is then deleted. Or, if the file gets too big, the database switches to another log file (with a higher id).
It is possible to force the log switching by using the CHECKPOINT command.
<p>
If the database file is corrupted, because the checksum of a record does not match (for example, if the
file was edited with another application), the database can be opened in recovery mode. In this case,
errors in the database are logged but not thrown. The database should be backed up to a script
and re-built as soon as possible. To open the database in the recovery mode, use a database URL
must contain RECOVER=1, as in jdbc:h2:test;RECOVER=1. Indexes are rebuilt in this case, and
the summary (object allocation table) is not read in this case, so opening the database takes longer.
<br /><a name="compatibility_modes"></a>
<h2>Compatibility Modes</h2>
All database engines behave a little bit different. For certain features,
this database can emulate the behavior of specific databases. Not all features or differences of those
databases are implemented. Currently, this feature is mainly used for randomized comparative testing
(where random statements are executed against multiple databases and the results are compared).
The mode can be changed by specifying the mode in the database URL, or using the SQL statement SET MODE.
To use the HSQLDB mode, you can use the database URL <code>jdbc:h2:test;MODE=HSQLDB</code>
or the SQL statement <code>SET MODE HSQLDB</code>.
Here is the list of currently supported modes and the difference to the regular mode:
<table>
<tr><th>Mode</th><th>Differences</th></tr>
<tr><td>
PostgreSQL
</td><td>
Concatenation of a NULL value with another value results in NULL.
Usually, the NULL is treated as an empty string if only one of the operators is NULL,
and NULL is only returned if both values are NULL.
</td></tr>
<tr><td>
MySQL
</td><td>
When inserting data, if a column is defined to be NOT NULL and a null value is inserted,
then a 0 (or empty string, or the current timestamp for timestamp columns) value is used.
Usually, this operation is not allowed and an exception is thrown.
</td></tr>
<tr><td>
HSQLDB
</td><td>
When converting the scale of decimal data, the number is only converted if the new scale is
smaller then current scale.
Usually, the scale is converted and 0s are added if required.
</td></tr>
</table>
<br /><a name="trace_options"></a>
<h2>Using the Trace Options</h2>
To find problems in an application, it is sometimes good to see what database operations
where executed. This database offers the following trace features:
<ul>
<li>Trace to System.out and/or a file
<li>Support for trace levels OFF, ERROR, INFO, and DEBUG
<li>The maximum size of the trace file can be set
<li>The Java code generation is possible
<li>Trace can be enabled at runtime by manually creating a file
</ul>
<h3>Trace Options</h3>
The simplest way to enable the trace option is setting it in the database URL.
There are two settings, one for System.out (TRACE_LEVEL_SYSTEM_OUT) tracing,
and one for file tracing (TRACE_LEVEL_FILE).
The trace levels are 0 for OFF, 1 for ERROR, 2 for INFO and 3 for DEBUG.
A database URL with both levels set to DEBUG is:
<pre>
jdbc:h2:test;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3
</pre>
The trace level can be changed at runtime by executing the SQL command
<code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for System.out tracing)
or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing).
Example:
<pre>
SET TRACE_LEVEL_SYSTEM_OUT 3
</pre>
<h3>Setting the Maximum Size of the Trace File</h3>
When using a high trace level, the trace file can get very big quickly.
The size of the file can be limited by executing the SQL statement
<code>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code>.
If the log file exceeds the limit, the file is renamed to .old and a new file is created.
If another .old file exists, it is deleted.
The default setting is 16 MB. Example:
<pre>
SET TRACE_MAX_FILE_SIZE 1
</pre>
<h3>Java Code Generation</h3>
When setting the trace level to INFO or DEBUG, Java source code is generated as well, so that
problem can be reproduced more easily. The trace file looks like this:
<pre>
...
12-20 20:58:09 jdbc[0]:
/**/dbMeta3.getURL();
12-20 20:58:09 jdbc[0]:
/**/dbMeta3.getTables(null, "", null, new String[]{"TABLE", "VIEW"});
...
</pre>
You need to filter out the lines without /**/ to get the Java source code.
In Windows, a simple way to do that is:
<pre>
find "**" test.trace.db > Trace.java
</pre>
Afterwards, you need to complete the file Trace.java before it can be compiled, for example with:
<pre>
import java.sql.*;
public class Trace { public static void main(String[]a)throws Exception {
Class.forName("org.h2.Driver");
...
}}
</pre>
Also, the user name and password needs to be set, because they are not listed in the trace file.
<h3>Enabling the Trace Option at Runtime by Manually Creating a File</h3>
Sometimes, you can't or don't want to change the application or database URL.
There is still a way to enable the trace mode in these cases, even at runtime (while
the database connection is open). You only need to create a special file in the directory
where the database files are stored.
The database engine checks every 4 seconds if this file exists (only while executing a statement).
The file name is the database name plus '.trace.db.start'.
<p>
Example: if a database is called 'test', then the file to start tracing is 'test.trace.db.start'.
The database engine tries to delete this file when it detects it.
If trace is enabled using the start file, the trace level is not persistent to the database, and
trace is switched back to the level that was set before when connecting to the database.
However, if the start file is read only, the database engine cannot delete the file and
will always enable the trace mode when connecting.
<br /><a name="read_only"></a>
<h2>Read Only Databases</h2>
If the database files are read-only, then the database is read-only as well.
It is not possible to create new tables, add or modify data in this database.
Only SELECT statements are allowed.
To create a read-only database, close the database so that the log file is deleted.
Then, make the database files read-only using the operating system.
When you open the database now, it is read-only.
There are two ways an application can find out a database is read-only:
By calling Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
<br /><a name="storage_formats"></a>
<h2>Binary and Text Storage Formats</h2>
This database engine supports both binary and text storage formats.
The binary format is faster, but the text storage format can be useful as well,
for example to debug the database engine.
If a database already exists, the storage format is recognized automatically.
New databases are created in the binary storage format by default.
To create a new database in the text storage format, the database URL must contain
the parameter STORAGE=TEXT. Example URL: jdbc:h2:test;STORAGE=TEXT
<br /><a name="low_disk_space"></a>
<h2>Graceful Handling of Low Disk Space Situations</h2>
The database is able to deal with situations where the disk space available is running low.
Whenever the database starts, an 'emergency space' file is created (size is 1 MB),
and if there is no more space available, the file will shrink. If the space available
is lower than 128 KB, the database will go into a special read only mode, where
writing operations are no longer allowed: All writing operations will throw the
exception 'No disk space available' from this point on. To go back to the normal operating
mode, all connections to the database need to be closed first, and space needs to
be freed up.
<p>
It is possible to install a database event listener to detect low disk space situations early on
(when only 1 MB if space is available). To do this, use the SQL statement
SET DATABASE_EVENT_LISTENER.
The listener can also be set at connection time, using an URL of the form
jdbc:h2:test;DATABASE_EVENT_LISTENER='com.acme.DbListener'
(the quotes around the class name are required).
See also the DatabaseEventListener API.
<h3>Opening a Corrupted Database</h3>
If a database can not be opened because the boot info (the SQL script that is run at startup)
is corrupted, then the database can be opened by specifying a database event listener.
The exceptions are logged, but opening the database will continue.
<br /><a name="computed_columns"></a>
<h2>Computed Columns / Function Based Index</h2>
Function indexes are not directly supported by this database, but they can be easily emulated
by using computed columns. For example, if an index on the upper-case version of
a column is required, just create a computed column with the upper-case version of the original column,
and index this column:
<pre>
CREATE TABLE ADDRESS(
ID INT PRIMARY KEY,
NAME VARCHAR,
UPPER_NAME VARCHAR AS UPPER(NAME)
);
CREATE INDEX IDX_U_NAME ON ADDRESS(UPPER_NAME);
</pre>
When inserting data, it is not required (better: not allowed) to specify a value for the upper-case
version of the column, because the value is generated. But you can use the
column when querying the table:
<pre>
INSERT INTO ADDRESS(ID, NAME) VALUES(1, 'Miller');
SELECT * FROM ADDRESS WHERE UPPER_NAME='MILLER';
</pre>
<br /><a name="multi_dimensional"></a>
<h2>Multi-Dimensional Indexes</h2>
A tool is provided to execute efficient multi-dimension (spatial) range queries.
This database does not support a specialized spatial index (R-Tree or similar).
Instead, the B-Tree index is used. For each record, the multi-dimensional key
is converted (mapped) to a single dimensional (scalar) value.
This value specifies the location on a space-filling curve.
<p>
Currently, Z-order (also called N-order or Morton-order) is used;
Hilbert curve could also be used, but the implementation is more complex.
The algorithm to convert the multi-dimensional value is called bit-interleaving.
The scalar value is indexed using a B-Tree index (usually using a computed column).
<p>
The method can result in a drastic performance improvement
over just using an index on the first column. Depending on the
data and number of dimensions, the improvement is usually higher than factor 5.
The tool generates a SQL query from a specified multi-dimensional range.
The method used is not database dependent, and the tool can easily be ported to other databases.
For an example how to use the tool, please have a look at the sample code provided
in TestMultiDimension.java.
<br /><a name="passwords"></a>
<h2>Using Passwords</h2>
<h3>Using Secure Passwords</h3>
Remember that weak passwords can be broken no matter of the encryption and security protocol.
Don't use passwords that can be found in a dictionary. Also appending numbers does not make them
secure. A way to create good passwords that can be remembered is, take the first
letters of a sentence, use upper and lower case characters, and creatively include special characters.
Example:
<p>
i'sE2rTpiUKtt (it's easy to remember this password if you know the trick)
<h3>Passwords: Using Char Arrays instead of Strings</h3>
Java Strings are immutable objects and cannot be safely 'destroyed' by the application.
After creating a String, it will remain in the main memory of the computer at least
until it is garbage collected. The garbage collection cannot be controlled by the application,
and even if it is garbage collected the data may still remain in memory.
It might also be possible that the part of memory containing the password
is swapped to disk (because not enough main memory is available).
<p>
An attacker might have access to the swap file of the operating system.
It is therefore a good idea to use char arrays instead of Strings to store passwords.
Char arrays can be cleared (filled with zeros) after use, and therefore the
password will not be stored in the swap file.
<p>
This database supports using char arrays instead of String to pass user and file passwords.
The following code can be used to do that:
<pre>
Class.forName("org.h2.Driver");
String url = "jdbc:h2:simple";
String user = "sam";
char[] password =
{'t','i','a','S','&amp;',E','t','r','p'};
Properties prop = new Properties();
prop.setProperty("user", user);
prop.put("password", password);
Connection conn = null;
try {
conn = DriverManager.
getConnection(url, prop);
} finally {
Arrays.fill(password, 0);
}
</pre>
In this example, the password is hard code in the application, which is not secure of course.
However, Java Swing supports a way to get passwords using a char array (JPasswordField).
<h3>Passing the User Name and/or Password in the URL</h3>
Instead of passing the user name as a separate parameter as in
<code>
Connection conn = DriverManager.
getConnection("jdbc:h2:test", "sa", "123");
</code>
the user name (and/or password) can be supplied in the URL itself:
<code>
Connection conn = DriverManager.
getConnection("jdbc:h2:test;USER=sa;PASSWORD=123");
</code>
The settings in the URL override the settings passed as a separate parameter.
<br /><a name="user_defined_functions"></a>
<h2>User Defined Functions and Stored Procedures</h2>
In addition to the built-in functions, this database supports user defined Java functions.
In this database, Java functions can be used as stored procedures as well.
A function must be declared (registered) before it can be used.
Only static Java methods are supported; both the class and the method must be public.
Example Java method:
<pre>
package org.h2.samples;
...
public class Function {
public static boolean isPrime(int value) {
return new BigInteger(String.valueOf(value)).isProbablePrime(100);
}
}
</pre>
The Java function must be registered in the database by calling CREATE ALIAS:
<pre>
CREATE ALIAS ISPRIME FOR "org.h2.samples.Function.isPrime"
</pre>
For a complete sample application, see src/test/org/h2/samples/Function.java.
<h3>Function Data Type Mapping</h3>
Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL.
In this case, the value NULL is used as the result. If the function should be called in this case, you need
to use 'java.lang.Integer' instead of 'int'.
<h3>Functions that require a Connection</h3>
If the first parameter in a Java function is a java.sql.Connection, then the connection
to database is provided. This connection does not need to be closed before returning.
<h3>Functions throwing an Exception</h3>
If a function throws an Exception, then the current statement is rolled back
and the exception is thrown to the application.
<h3>Functions returning a Result Set</h3>
Functions may returns a result set. Such a function can be called with the CALL statement:
<pre>
public static ResultSet query(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql);
}
CREATE ALIAS QUERY FOR "org.h2.samples.Function.query";
CALL QUERY('SELECT * FROM TEST');
</pre>
<h3>Using SimpleResultSet</h3>
A function that returns a result set can create this result set from scratch using the SimpleResultSet tool:
<pre>
import org.h2.tools.SimpleResultSet;
...
public static ResultSet simpleResultSet() throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ID", Types.INTEGER, 10, 0);
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addRow(new Object[] { new Integer(0), "Hello" });
rs.addRow(new Object[] { new Integer(1), "World" });
return rs;
}
CREATE ALIAS SIMPLE FOR "org.h2.samples.Function.simpleResultSet";
CALL SIMPLE();
</pre>
<h3>Using a Function as a Table</h3>
A function returning a result set can be like a table.
However, in this case the function is called at least twice:
First while parsing the statement to collect the column names
(with parameters set to null where not known at compile time).
And then, while executing the statement to get the data (may be repeatedly if this is a join).
If the function is called just to get the column list, the URL of the connection passed to the function is
jdbc:columnlist:connection. Otherwise, the URL of the connection is jdbc:default:connection.
<pre>
public static ResultSet getMatrix(Integer id) throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("X", Types.INTEGER, 10, 0);
rs.addColumn("Y", Types.INTEGER, 10, 0);
if(id == null) {
return rs;
}
for(int x = 0; x < id.intValue(); x++) {
for(int y = 0; y < id.intValue(); y++) {
rs.addRow(new Object[] { new Integer(x), new Integer(y) });
}
}
return rs;
}
CREATE ALIAS MATRIX FOR "org.h2.samples.Function.getMatrix";
SELECT * FROM MATRIX(3) WHERE X>0;
</pre>
<br /><a name="triggers"></a>
<h2>Triggers</h2>
This database supports Java triggers that are called before or after a row is updated, inserted or deleted.
Triggers can be used for complex consistency checks, or to update related data in the database.
It is also possible to use triggers to simulate materialized views.
For a complete sample application, see src/test/org/h2/samples/TriggerSample.java.
A Java trigger must implement the interface org.h2.api.Trigger:
<pre>
import org.h2.api.Trigger;
...
public class TriggerSample implements Trigger {
public void init(String triggerName, String tableName) {
}
public void fire(Connection conn,
Object[] oldRow, Object[] newRow)
throws SQLException {
}
}
</pre>
The connection can be used to query or update data in other tables.
The trigger then needs to be defined in the database:
<pre>
CREATE TRIGGER INV_INS AFTER INSERT ON INVOICE
FOR EACH ROW CALL "org.h2.samples.TriggerSample"
</pre>
The trigger can be used to veto a change, by throwing a SQL Exception.
<br /><a name="compacting"></a>
<h2>Compacting a Database</h2>
Empty space in the database file is re-used automatically.
To re-build the indexes, the most simple way is to delete the .index.db file
while the database is closed. However in some situations (for example after deleting
a lot of data in a database), one sometimes wants to shrink the size of the database
(compact a database). Here is a sample function to do this:
<pre>
public static void compact(String dir, String dbName,
String user, String password) throws Exception
String url = "jdbc:h2:" + dbName;
String script = "test.sql";
Backup.execute(url, user, password, script);
DeleteDbFiles.execute(dir, dbName);
RunScript.execute(url, user, password, script);
}
</pre>
See also the sample application org.h2.samples.Compact.
The commands SCRIPT / RUNSCRIPT can be used as well to create the a backup
of a database and re-build the database from the script.
<br /><a name="cache_settings"></a>
<h2>Cache Settings</h2>
<p>
The database keeps most frequently used data and index pages in the main memory.
The amount of memory used for caching can be changed using the setting
CACHE_SIZE. This setting can be set in the database connection URL
(jdbc:h2:test;CACHE_SIZE=200000), or it can be changed at runtime using
SET CACHE_SIZE size.
</p>
<p>
This database supports two cache page replacement algorithms: LRU (the default) and
2Q. For LRU, the pages that were least frequently used are removed from the
cache if it becomes full. The 2Q algorithm is a bit more complicated, basically two
queues are used. The 2Q algorithm is more resistent to table scans, however the overhead
is a bit higher compared to the LRU. To use the cache algorithm 2Q, use a database URL
of the form jdbc:h2:test;CACHE_TYPE=TQ. The cache algorithm can not be changed
once the database is open.
</p>
<p>
To get information about page reads and writes, and the current caching algorithm in use,
call SELECT * FROM INFORMATION_SCHEMA.SETTINGS. The number of pages read / written
is listed for the data and index file.
</p>
</div></td></tr></table></body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>H2 Database Engine</title>
<script type="text/javascript" src="navigation.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link rel="alternate" type="application/atom+xml" title="H2 Newsfeed" href="http://www.h2database.com/html/newsfeed-atom.xml" />
<link rel="alternate" type="application/rss+xml" title="H2 Newsfeed" href="http://www.h2database.com/html/newsfeed-rss.xml" />
</head>
<frameset cols="180,*" rows="*" frameborder="2" framespacing="4" border="4" onLoad="loadFrameset()">
<frame frameborder="0" marginheight=0 marginwidth=0 src="search.html" name="menu">
<frame frameborder="0" marginheight=0 marginwidth=0 src="main.html" name="main">
</frameset>
<noframes>
<body>
H2 (for 'Hypersonic 2') is free a Java SQL DBMS.
Clustering, embedded and server mode, transactions, referential integrity,
views, subqueries, triggers, encryption, and disk based or in-memory operation
are supported. A browser based console application is included.
If you see this page your browser does not support frames.
Please click here to view the <a href="search.html">index</a>.
</body>
</noframes>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Functions
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Functions</h1>
<h2>Aggregate Functions</h2>
<c:forEach var="item" items="functionsAggregate">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>Numeric Functions</h2>
<c:forEach var="item" items="functionsNumeric">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>String Functions</h2>
<c:forEach var="item" items="functionsString">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>Time and Date Functions</h2>
<c:forEach var="item" items="functionsTimeDate">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>System Functions</h2>
<c:forEach var="item" items="functionsSystem">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<c:forEach var="item" items="functionsAll">
<br>
<a name="sql${item.id}"></a><h3>${item.topic}</h3>
<pre>
${item.syntax}
</pre>
${item.text}
<p>
<b>Example:</b><br>
${item.example}
<br>
</c:forEach>
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
SQL Grammar
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>SQL Grammar</h1>
<h2>Commands (Data Manipulation)</h2>
<c:forEach var="item" items="commandsDML">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>Commands (Data Definition)</h2>
<c:forEach var="item" items="commandsDDL">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>Commands (Other)</h2>
<c:forEach var="item" items="commandsOther">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<h2>Other Grammar</h2>
<c:forEach var="item" items="otherGrammar">
<a href="#sql${item.id}">${item.topic}</a><br>
</c:forEach>
<c:forEach var="item" items="commands">
<br>
<a name="sql${item.id}"></a><h3>${item.topic}</h3>
<pre>
${item.syntax}
</pre>
${item.text}
<p>
<b>Example:</b><br>
${item.example}
<br>
</c:forEach>
<c:forEach var="item" items="otherGrammar">
<br>
<a name="sql${item.id}"></a><h3>${item.topic}</h3>
<pre>
${item.syntax}
</pre>
${item.text}
<p>
<b>Example:</b><br>
${item.example}
<br>
</c:forEach>
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
History
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>History and Roadmap</h1>
<a href="#history">
History of this Database Engine</a><br />
<a href="#changelog">
Change Log</a><br />
<a href="#roadmap">
Roadmap</a><br />
<br /><a name="history"></a>
<h2>History of this Database Engine</h2>
The development of H2 was started in May 2004,
but it was first published on December 14th 2005.
The author of H2, Thomas Mueller, is also the original developer of Hypersonic SQL.
In 2001, he joined PointBase Inc. where he created PointBase Micro.
At that point, he had to discontinue Hypersonic SQL, but then the HSQLDB Group was formed
to continued to work on the Hypersonic SQL codebase.
The name H2 stands for Hypersonic 2; however H2 does not share any code with
Hypersonic SQL or HSQLDB. H2 is built from scratch.
<br /><a name="changelog"></a>
<h2>Change Log</h2>
<h3>Version 1.0 (Current)</h3>
<h3>Version 1.0 / 2006-12-..</h3><ul>
<li>String.toUpperCase and toLowerCase can not be to processing SQL, as they depend on the current locale.
Now use toUpperCase(Locale.ENGLISH) or Character.toUpperCase(..)
<li>Table aliases are now supported in DELETE and UPDATE. Example: DELETE FROM TEST T0.
<li>The RunScript tool can now include other files using a new syntax: @INCLUDE fileName.
It was already possible to do that using embedded RUNSCRIPT statements, but not remotely.
<li>When the database URL contains ;RECOVERY=TRUE then the index file is now deleted if it was not closed before.
<li>The scale of a NUMERIC(1) column is now 0. It used to be 32767.
<li>Deleting old temp files now uses a phantom reference queue. Generally, temp files should now be deleted
earlier.
<li>Opening a large database is now much faster when even when using the default log mode (LOG=1),
if the database was closed previously.
<li>Very large BLOBs and CLOBs can now be used with the server and the cluster mode.
The objects will temporarily be buffered on the client side if they are larger than some
size (currently 64 KB).
<li>PreparedStatement.setObject(x, y, Types.OTHER) does now serialize the object in every case
(even for Integer).
<li>EXISTS subqueries with parameters were not re-evaluated when the prepared statement was
reused. This could lead to incorrect results.
<li>Support for indexed parameters in PreparedStatements: update test set name=?2 where id=?1
</ul>
<h3>Version 1.0 / 2006-12-03</h3><ul>
<li>The SQL statement COMMENT did not work as expected. Many bugs have been fixed in this area.
If you already have comments in the database, it is recommented to backup and restore the database,
using the Backup and RunScript tools or the SQL commands SCRIPT and RUNSCRIPT.
<li>Mixing certain data types in an operation, for example VARCHAR and TIMESTAMP, now converts both expressions to TIMESTAMP.
This was a problem when comparing a string against a date.
<li>Improved performance for CREATE INDEX. This method is about 10% faster if the original order is random.
<li>Server: If an object was already closed on the server side because it was too 'old' (not used for a long time),
even calling close() threw an exception. This is not done any more as it is not a problem.
<li>Optimization: The left and right side of a AND and OR conditions are now ordered by the expected cost.
<li>There was a bug in the database encryption algorithm. The initalization vector was not correctly calculated, and
pattern of repeated encrypted bytes where generated for empty blocks in the file. This has been is fixed.
The security of the data itself was not compromised, but this was not the intended behaviour.
If you have an encrypted database, you will need to decrypt the database using the org.h2.tools.ChangePassword
(using the old database engine), and encrypt the database using the new engine. Alternatively, you can
use the Backup and RunScript tools or the SQL commands SCRIPT and RUNSCRIPT.
<li>New connection time setting CACHE_TYPE=TQ to use the 2Q page replacement algorithm.
The overall performance seems to be a bit better when using 2Q. Also, 2Q should be more resistant to table scan.
<li>Change behaviour: If both sides of a comparison are parameters with unknown data type, then an exception is thrown now.
The same happens for UNION SELECT if both columns are parameters.
<li>New system function SESSION_ID().
<li>Deeply nested views where slow to execute, because the query was parsed many times. Fixed.
<li>The service wrapper is now included in the default installation and documented.
<li>Java functions returning a result set (such as CSVREAD) now can be used in a SELECT statement like a table.
The function is still called twice (first to get the column list at parse time, and then at execute time).
The behaviour has been changed: Now first call contains the values if set, but the connection URL is different
(jdbc:columnlist:connection instead of jdbc:default:connection).
</ul>
<h3>Version 1.0 / 2006-11-20</h3><ul>
<li>SCRIPT: New option BLOCKSIZE to split BLOBs and CLOBs into separate blocks, to avoid OutOfMemory problems.
<li>When using the READ_COMMITTED isolation level, a transaction now waits until there are no write locks
when trying to read data. However, it still does not add a read lock.
<li>INSERT INTO ... SELECT ... and ALTER TABLE with CLOBs and/or BLOBs did not work. Fixed.
<li>CSV tool: the methods setFieldSeparatorWrite and setRowSeparatorWrite where not accessible.
The API has been changed, there is now only one static method, getInstance().
<li>ALTER TABLE ADD did throw a strange message if the table contained views. Now the message is better,
but it is still not possible to do that if views on this table exist.
<li>Direct links to the Javadoc were not working.
<li>CURRVAL and NEXTVAL functions: New optional sequence name parameter.
<li>ALTER TABLE: If there was a foreign key in another table that references to the change table,
the constraint was dropped.
<li>The input streams returned from this database did not always read all data when calling
read. This was not wrong, but unexpected. Now changed that read behaves like readFully.
<li>The default cache size is now 65536 pages instead of 32768. Like this the memory used for caching
is about 10 MB. Before, it used to be about 6 MB.
<li>Inserting rows into linked tables did not work for HSQLDB when the value was NULL.
Now NULL values are inserted if the value for a column was not set in the insert statement.
<li>New optimization to reuse subquery results. Can be disabled with SET OPTIMIZE_REUSE_RESULTS 0.
<li>Oracle SYNONYM tables are now listed in the H2 Console.
<li>CREATE LINKED TABLE didn't work for Oracle SYNONYM tables. Fixed.
<li>Dependencies between the JDBC client and the database have been removed.
The h2client.jar is now 295 KB. There are still some classes included that should not be there.
The theoretical limit is about 253 KB currently.
<li>When using the server version, when not closing result sets or using nested DatabaseMetaData result sets,
the connection could break. This has been fixed.
<li>EXPLAIN... results are now formatted on multiple lines so it is easier to read them.
<li>The Spanish translation was completed by Miguel Angel. Thanks a lot! Translations to other languages are always welcome.
<li>New system function SCHEMA() to get the current schema.
<li>New SQL statement SET SCHEMA to change the current schema of this session.
<li>The Recovery tool has been improved. It now creates a SQL script file that can be executed directly.
<li>LENGTH now returns the precision for CLOB, BLOB, and BINARY (and is therefore faster).
<li>The built-in FTP server can now access a virtual directory stored in a database.
</ul>
<h3>Version 1.0 / 2006-11-03</h3><ul>
<li>
Two simple full text search implementations (Lucene and native) are now included.
This is work in progress, and currently undocumented.
See test/org/h2/samples/fullTextSearch.sql.
To enable the Lucene implementation, you first need to install Lucene,
rename FullTextLucene.java.txt to *.java and call 'ant compile'.
<li>
Wide b-tree indexes (with large VARCHAR columns for example) could get corrupted. Fixed.
<li>
If a custom shutdown hook was installed, and the database was called at shutdown,
a NullPointException was thrown. Now, the following exception is thrown:
Database called at VM shutdown; add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL to disable automatic database closing
<li>
If SHUTDOWN was called and DB_CLOSE_DELAY was set, the database was not closed.
This has been changed so that shutdown always closes the database.
<li>
Subqueries with order by outside the column list didn't work correctly. Example:
SELECT (SELECT NAME FROM TEST ORDER BY ID);
This is fixed now.
<li>
Linked Tables: Only the first column was linked when linking to PostgreSQL, or a subquery. Fixed.
<li>
Sequences: When the database is not closed normally, the value was not set correctly. Fixed.
<li>
The optimization for IN(SELECT...) was too agressive; changes in the inner query where not accounted for.
<li>
Index names of referential constraints are now prefixed with the constraint name.
<li>
Blob.getBytes skipped the wrong number of bytes. Fixed.
<li>
Group by a function didn't work if a column list was specified in the select list. Fixed.
<li>
Improved search functionality in the HTML documentation.
<li>
Triggers can now be defined on a list of actions (for example: INSERT, UPDATE) instead of just one action per trigger.
<li>
On some systems (for example, some Linux VFAT and USB flash disk drivers), RandomAccessFile.setLength does not work correctly.
A workaround for this problem has been implemented.
<li>
DatabaseMetaData.getTableTypes now also returns SYSTEM TABLE and TABLE VIEW.
This was done for DbVisualizer. Please tell me if this breaks other applications or tools.
<li>
Java functions with Blob or Clob parameters are now supported.
<li>
LOCK_MODE 0 (READ_UNCOMMITTED) did not work when using multiple connections.
Fixed, however LOCK_MODE 0 should still not be used when using multiple connections.
<li>
New SQL statement COMMENT ON ... IS ...
<li>
Added a 'remarks' column to most system tables.
New system table INFORMATION_SCHEMA.TRIGGERS
<li>
PostgreSQL compatibility: Support for the date format 2006-09-22T13:18:17.061
<li>
MySQL compatibility: ResultSet.getString("PEOPLE.NAME") is now supported.
<li>
JDBC 4.0 driver auto discovery: When using JDK 1.6, Class.forName("org.h2.Driver") is no longer required.
</ul>
<h3>Version 1.0 / 2006-10-10</h3><ul>
<li>
Redundant () in a IN subquery is now supported: where id in ((select id from test))
<li>
The multi-threaded kernel can not be enabled using SET MULTI_THREADED 1 or jdbc:h2:test;MULTI_THREADED=1.
A new tests has been written for this feature, but more tests are required, so this is still experimental.
<li>
Can now compile everything with JDK 1.6. However, only very few of the JDBC 4.0 features are implemented so far.
<li>
A small FTP server is now included. Disabled by default. Intended as a simple mechanism to transfer data in ad-hoc networks.
<li>
GROUP BY an formula or function didn't work if the same expression was used in the select list. Fixed.
<li>
Reconnect didn't work after renaming a user if rights were granted for this user. Fixed.
<li>
Opening and closing connections in many threads sometimes failed because opening a session
was not correctly synchronized. Fixed.
<li>
Function aliases may optionally include parameter classes. Example:
CREATE ALIAS PARSEINT2 FOR "java.lang.Integer.parseInt(java.lang.String, int)"
<li>
Support for UUID
<li>
Support for DOMAIN (user defined data types).
<li>
Could not re-connect to a database when ALLOW_LITERALS or COMPRESS_LOB was set. Fixed.
</ul>
<h3>Version 1.0 / 2006-09-24</h3><ul>
<li>
New LOCK_MODE 3 (READ_COMMITTED). Table level locking, but only when writing (no read locks).
<li>
Connection.setTransactionIsolation and getTransactionIsolation now set / get the LOCK_MODE of the database.
<li>
New system function LOCK_MODE()
<li>
Optimizations for WHERE ... IN(...) and SELECT MIN(..), MAX(..) are now enabled by default, but can be disabled
in the application (Constants.OPTIMIZE_MIN_MAX, OPTIMIZE_IN)
<li>
LOBs are now automatically converted to files. Constants.AUTO_CONVERT_LOB_TO_FILES is now set to true by default,
however this can be disabled in the application.
<li>
Reading from compressed LOBs didn't work in some cases. Fixed.
<li>
CLOB / BLOB: Copying LOB data directly from one table to another, and altering a table with with LOBs did not work,
the BLOB data was deleted when the old table was deleted. Fixed.
<li>
Wide b-tree indexes (with large VARCHAR columns for example) with a long common prefix (where many
rows start with the same text) could get corrupted. Fixed.
<li>
For compatibility with Derby, the precision in a data type definition can now include K, M or G as in BLOB(10M).
<li>
CREATE TABLE ... AS SELECT ... is now supported.
<li>
DROP TABLE: Can now drop more than one column in one step: DROP TABLE A, B
<li>
CREATE SCHEMA: The authorization part is now optional.
<li>
Protection against SQL injection: New command SET ALLOW_LITERALS {NONE|ALL|NUMBERS}.
With SET ALLOW_LITERALS NONE, SQL injections are not possible because literals in SQL statements are rejected;
User input must be set using parameters ('?') in this case.
<li>
New concept 'Constants': New SQL statements CREATE CONSTANT and DROP CONSTANT. Constants can be used
where expressions can be used. New metadata table INFORMATION_SCHEMA.CONSTANTS.
Built-in constant function ZERO() to get the integer value 0.
<li>
New data type OTHER (alternative names OBJECT and JAVA_OBJECT). When using this data type,
Java Objects are automatically serialized and deserialized in the JDBC layer. Constants.SERIALIZE_JAVA_OBJECTS is
now true by default.
<li>
[NOT] EXISTS(SELECT ... EXCEPT SELECT ...) did not work in all cases. Fixed.
<li>
DatabaseMetaData.getProcedures and getProcedureColumns are implemented now.
INFORMATION_SCHEMA.FUNCTION_ALIASES was changed, and there is a new table
INFORMATION_SCHEMA.FUNCTION_COLUMNS.
<li>
As a workaround for a problem on (maybe misconfigured) Linux system, now use
InetAddress.getByName("127.0.0.1") instead of InetAddress.getLocalHost() to get the loopback address.
<li>
Functions returning a result set that are used like a table are now first called
(to get the column names) with null values (or 0 / false for primitive types)
as documented and not with any values even if they are constants.
<li>
Improved performance for MetaData calls. The table name is now indexed.
<li>
BatchUpdateException was not helpful, now includes the cause
<li>
Unknown setting in the database URL (which are most likely typos) are now detected and
an exception is thrown. Unknown settings in the connection properties however
(for example used by OpenOffice and Hibernate) are ignored.
<li>
Now the log size is automatically increased to at least 10% of the data file.
This solves a problem with 'Too many open files' for very large databases.
<li>
Backup and Runscript tools now support options (H2 only)
</ul>
<h3>Version 1.0 / 2006-09-10</h3><ul>
<li>
Updated the performance test so that Firebird can be tested as well.
<li>
Now an exception is thrown when the an overflow occurs for mathematical operations (sum, multiply and so on)
for the data type selected.
<li>
Correlated subqueries: It is now possible to use columns of the outer query
in the select list of the inner query (not only in the condition).
<li>
The script can now be compressed. Syntax: SCRIPT TO 'file' COMPRESSION {DEFLATE|LZF|ZIP|GZIP}.
<li>
New setting SET COMPRESS_LOB {NO|LZF|DEFLATE} to automatically compress BLOBs and CLOBs.
This is helpful when storing highly redundant textual data (XML, HTML).
<li>
ROWNUM didn't always work as expected when using subqueries. This is fixed now.
However, there is no standard definition for ROWNUM, for situations where you want to limit
the number of rows (specially for offset), the standardized LIMIT [OFFSET] should be used
<li>
Deleting many rows from a table with a self-referencing constraint with 'on delete cascade' did not work.
Now referencial constraints are checked after the action is performed.
<li>
The cross references in the SQL grammar docs where broken in the last release.
<li>
There was a bug in the default settings for the Console, the setting
;hsqldb.default_table_type=cached was added to the H2 database instead of the HSQLDB database.
<li>
Workaround for an OpenOffice.org problem: DatabaseMetaData calls with schema name pattern
now return the objects for the PUBLIC schema if the schema name pattern was an empty string.
<li>
Until now, unknown connection properties where ignored (for OpenOffice compatibility).
This is not a good solution because typos are not detected.
This behaviour is still the default but it can be disabled by adding
;IGNORE_UNKNOWN_SETTINGS=FALSE to the database URL.
However this is not the final solution.
<li>
Workaround for an OpenOffice problem: OpenOffice Base calls DatabaseMetaData functions with "" as the catalog.
As the catalog in H2 is not an empty string, the result should strictly be empty; however to make OpenOffice work,
the catalog is not used as a criteria in this case.
<li>
New SQL statement DROP ALL OBJECTS [DELETE FILES] to drop all tables, sequences and so on. If DELETE FILES is added,
the database files are deleted as well when the last connection is closed. The DROP DATABASE statement found in other systems
means drop another database, while DROP ALL OBJECTS means remove all data from the current database.
<li>
When running a script that contained referential or unique constraints, and if the indexes for those constraints are not created by the user,
a internal exception could occur. This is fixed. Also, the script command will no longer write the internal indexes used into the file.
<li>
SET IGNORECASE is now supported for compatiblity with HSQLDB, and because using collations (SET COLLATION) is very slow on JDKs (JDK 1.5)
<li>
ORDER BY an expression didn't work when using GROUP BY at the same time.
</ul>
<h3>Version 1.0 / 2006-08-31</h3><ul>
<li>
In some situations, wide b-tree indexes (with large VARCHAR columns for example) could get corrupted. Fixed.
<li>
ORDER BY was broken in the last release when using table aliases. Fixed.
</ul>
<h3>Version 0.9 / 2006-08-28</h3><ul>
<li>
DATEDIFF on seconds, minutes, hours did return different results in certain timezones (half-hour timezones)
in certain situations. Fixed.
<li>
LOB files where not deleted when the table was truncated or dropped. This is now done.
<li>
When large strings or byte arrays where inserted into a LOB (CLOB or BLOB), or if the data was stored
using PreparedStatement.setBytes or setString, the data was stored in-place (no separate files where created).
This is now implemented (that means distinct files are created in every case), however disabled by default.
It is possible to enable this option with Constants.AUTO_CONVERT_LOB_TO_FILES = true
<li>
New setting MAX_LENGTH_INPLACE_LOB
<li>
When reading from a table with many small CLOB columns, in some situations
an ArrayIndexOutOfBoundsException was thrown. Fixed.
<li>
Optimization for MIN and MAX (but currently disabled by default until after release 1.0):
Queries such as SELECT MIN(ID), MAX(ID)+1, COUNT(*) FROM TEST now use an index if one is available.
To enable manually, set Constants.OPTIMIZE_MIN_MAX = true in your application.
<li>
Subqueries: Constant subqueries are now only evaluated once (like this was before).
<li>
Linked tables: Improved compatibility with other databases and improved error messages.
<li>
Linked tables: The table name is no longer quoted when accessing the foreign database.
This allows to use schema names, and possibly subqueries as table names (when used in queries).
<li>
Outer join: There where some incompatibilities with PostgreSQL and MySQL with more complex outer joins. Fixed.
</ul>
<h3>Version 0.9 / 2006-08-23</h3><ul>
<li>
Bugfix for LIKE: If collation was set (SET COLLATION ...), it was ignored when using LIKE. Fixed.
<li>
Optimization for IN(value list) and IN(subquery). The optimization is disabled by default,
but can be switched on by setting Constants.OPTIMIZE_IN = true
(no compilation required). Currently, the IN(value,...) is converted to BETWEEN min AND max,
that means it is not converted to an inner join.
<li>
Arithmetic overflows in can now be detected for sql types TINYINT, SMALLINT, INTEGER, BIGINT.
Operations: addition, subtraction, multiplication, negation. By default, this detection is switched off
but can be switched on by setting Constants.OVERFLOW_EXCEPTIONS = true
(no compilation required).
<li>
Referential integrity: fixed a stack overflow problem when a deleted record caused (directly or indirectly)
deleting other rows in the same table via cascade delete.
<li>
Database opening: sometimes opening a database was very slow because indexes were re-created.
even when the index was consistent. This lead to long database opening times for some databases. Fixed.
<li>
Local temporary tables where not included in the meta data. Fixed.
<li>
Very large transactions are now supported. The undo log of large transactions is buffered to disk.
The maximum size of undo log records to be kept in-memory can be changed with SET MAX_MEMORY_UNDO.
Currently, this feature is disabled by default (MAX_MEMORY_UNDO is set to Integer.MAX_VALUE by default) because it needs more testing.
It will be enabled after release 1.0.
The current implementation has a limitation: changes to tables without a primary key can not be buffered to disk
<li>
Improvements in the autocomplete feature. Thanks a lot to James Devenish for his very valuable feedback and testing!
<li>
Bugfix for an outer join problem (too many rows where returned for a combined inner join / outer join).
<li>
Date and time constants outside the valid range (February 31 and so on) are no longer accepted.
</ul>
<h3>Version 0.9 / 2006-08-14</h3><ul>
<li>
SET LOG 0 didn't work (except if the log level was set to some other value before). Fixed.
<li>
Outer join optimization. An outer join now evaluates expressions like (ID=1) in the where clause early.
However expressions like ID IS NULL or NOT ID IS NOT NULL in the where clause can not be optimized.
<li>
Autocomplete is now improved.
Schemas and quoted identifiers are not yet supported.
There are some browser incompatibilities,
for example Enter doesn't work in Opera (but clicking on the item does),
clicking on the item doesn't work in Internet Explorer (but Enter works).
However everything should work in Firefox. Please report any incompatibilities.
<li>
Source code to support H2 in Resin is included (see src/tools, package com.caucho.jdbc).
For the complete patch, see http://forum.caucho.com/node/61
<li>
Space is better re-used after deleting many records.
<li>
Umlauts and chinese characters are now supported in
identifier names (table name, column names and so on).
<li>
Fixed a problem when comparing BIGINT values with constants.
<li>
NULL handling was wrong for: true IN (true, null). Fixed.
<li>
It was not possible to cancel a select statement with a (temporary) view. Fixed.
</ul>
<h3>Version 0.9 / 2006-07-29</h3><ul>
<li>
ParameterMetaData is now implemented (mainly to support getParameterCount).
<li>
Improved performance for Statement.getGeneratedKeys().
<li>
SCRIPT: The system generated indexes are now not included in the script file because they will be created automatically.
Also, the drop statements for generated sequences are not included in the script any longer.
<li>
Bugfix: IN(NULL) didn't return NULL in every case. Fixed.
<li>
Bugfix: DATEDIFF didn't work correctly for hour, minute and second if one of the dates was before 1970. Fixed.
<li>
Shutdown TCP Server: The Server tool didn't throw / print a meaningful exception
if the server was not running or if the password was wrong. Fixed.
<li>
Experimental auto-complete functionality in the H2 Console.
Does not yet work for all cases. Press [Ctrl]+[Space] to activate, and [Esc] to deactivate it.
<li>
SELECT EXCEPT (or MINUS) did not work for some cases. Fixed.
<li>
DATEDIFF now returns a BIGINT and not an INT
<li>
1.0/3.0 is now 0.33333... and not 0.3 as before. The scale of a DECIMAL division is
adjusted automatically (up to current scale + 25).
<li>
'SELECT * FROM TEST' can now be written as 'FROM TEST SELECT *'
to enable improved autocomplete (column names can be suggested in the
SELECT part of the query because the tables are known if the FROM part comes first).
SELECT is now a keyword.
<li>
H2 Console: First version of an autocomplete feature.
<li>
DATEADD didn't work for milliseconds. Fixed.
<li>
New parameter schemaName in Trigger.init.
<li>
New method DatabaseEventListener.init to pass the database URL.
<li>
Opening a database that was not closed previously is now faster
(specially if using a database URL of the form jdbc:h2:test;LOG=2)
Applying the redo-log is buffered and writing to the file is ordered.
<li>
Could not connect to a database that was closing at the same time.
<li>
C-style block comments /* */ are not parsed correctly when they contain * or /
</ul>
<h3>Version 0.9 / 2006-07-14</h3><ul>
<li>
The regression tests are no longer included in the jar file. This reduces the size by about 200 KB.
<li>
Fixed some bugs in the CSV tool. This tool should now work for most cases, but is still not fully tested.
<li>
The cache size is now measured in blocks and no longer in rows. Manually setting
the cache size is no longer necessary in most cases.
<li>
Objects of unknown type are no longer serialized to a byte array (and deserialized when calling getObject on a byte array data type)
by default. This behaviour can be changed with Constants.SERIALIZE_JAVA_OBJECTS = true
<li>
New column IS_GENERATED in the metadata tables SEQUENCES and INDEXES
<li>
Optimization: deterministic subqueries are evaluated only once.
<li>
An exception was thrown if a scalar subquery returned no rows. Now the NULL value is used in this case.
<li>
IF EXISTS / IF NOT EXISTS implemented for the remaning CREATE / DROP statements.
<li>
ResultSetMetaData.isNullable is now implemented.
<li>
LIKE ... ESCAPE: The escape character may now also be an expression.
<li>
Compatibility: TRIM(whitespace FROM string)
<li>
Compatibility: SUBSTRING(string FROM start FOR length)
<li>
CREATE VIEW now supports a column list: CREATE VIEW TESTV(A, B) AS ...
<li>
Compatibility: 'T', 'Y', 'YES', 'F', 'N', 'NO' (case insensitive) can now also be converted to boolean.
This is allowed now: WHERE BOOLEAN_FIELD='T'=(ID>1)
<li>
Optimization: data conversion of constants was not optimized. This is done now.
<li>
Compatibility: Implemented a shortcut version to declare single column referential integrity:
CREATE TABLE TEST(ID INT PRIMARY KEY, PARENT INT REFERENCES TEST)
<li>
Issue #126: It is possible to create multiple primary keys for the same table.
<li>
Issue #125: Foreign key constraints of local temporary tables are not dropped when the table is dropped.
<li>
Issue #124: Adding a column didn't work when the table contains a referential integrity check.
<li>
Issue #123: The connection to the server is lost if an abnormal exception occurs.
Example SQL statement: select 1=(1,2)
<li>
The H2 Console didn't parse statements containing '-' or '/' correctly. Fixed.
Now uses the same facility to split a script into SQL statements for
the RunScript tool, for the RUNSCRIPT command and for the H2 Console.
<li>
DatabaseMetaData.getTypeInfo: BIGINT was returning AUTO_INCREMENT=TRUE, which is wrong. Fixed.
</ul>
<h3>Version 0.9 / 2006-07-01</h3><ul>
<li>
After dropping contraints and altering a table sometimes the database could not be opened. Fixed.
<li>
Outer joins did not always use an index even if this was possible. Fixed.
<li>
Issue #122: Using OFFSET in big result sets (disk buffered result sets) did not work. Fixed.
<li>
Support DatabaseMetaData.getSuperTables (currently returns an empty result set in every case).
<li>
Database names are no longer case sensitive for the Windows operating system,
because there the files names are not case sensitive.
<li>
If an index is created for a constraint, this index now belong to the constraint and is removed when removing the constraint.
<li>
Issue #121: Using a quoted table or alias name in front of a column name (SELECT "TEST".ID FROM TEST) didn't work.
<li>
Issue #120: Some ALTER TABLE statements didn't work when the table was in another than the main schema. Fixed.
<li>
Issue #119: If a table with autoincrement column is created in another schema,
it was not possible to connect to the database again.
Now opening a database first sorts the script by object type.
<li>
Issue #118: ALTER TABLE RENAME COLUMN doesn't work correctly. Workaround: don't use it.
<li>
Cache: implemented a String cache and improved the Value cache. Now uses a weak reference
to avoid OutOfMemory due to caching values.
<li>
Server: changed the public API a bit to allow an application to deal easier with start problems.
Now instead of Server.startTcpServer(args) use Server.createTcpServer(args).start();
<li>
Issue #117: Server.start...Server sometimes returned before the server was started. Solved.
<li>
Issue #116: Server: reduces memory usage. Reduced number of cached objects per connection.
<li>
Improved trace messages, and trace now starts earlier (when opening the database).
<li>
Simplified translation of the Web Console (a tool to convert the translation files to UTF-8).
<li>
Newsfeed sample application (used to create the newsfeed and newsletter).
<li>
New functions: MEMORY_FREE() and MEMORY_USED().
</ul>
<h3>Version 0.9 / 2006-06-16</h3><ul>
<li>
Implemented distributing lob files into directories, and only keep up to 255 files in one directory.
However this is disabled by default; it will be enabled the next time the file format changes
(maybe not before 1.1). It can be enabled by the application by setting
Constants.LOB_FILES_IN_DIRECTORIES = true;
<li>
If a connection is closed while there is still an operation running, this operation is stopped (like when calling Statement.cancel).
<li>
Issue #115: If three or more threads / connections are used, sometimes lock timeout exceptions can occur when they should not. Solved.
<li>
Calling Server.start...Server now doesn't return until the server socket is ready to accept connections.
<li>
Issue #112: Two threads could not open the same database at the same time. Solved.
This was only a problem when the database was opened in a non-standard was, without using DriverManager.getConnection.
<li>
Implemented DROP TRIGGER.
<li>
Issue #113: Drop is now restricted: can only drop sequences / functions / tables if nothing depends on them.
<li>
Issue #114: Support large index data size. Before, there was a limit of around 1000 bytes per row.
<li>
Blob.getLength() and Clob.getLength() are now fast operations and don't read the whole object any longer.
<li>
Issue #111: The catalog name in the DatabaseMetaData calls and Connection.getCatalog was lowercase;
some applications may not work because they expect it to be uppercase.
<li>
Issue #110: PreparedStatement.setCharacterStream(int parameterIndex, Reader reader, int length) and
ResultSet.updateCharacterStream(...) didn't work correctly for 'length' larger than 0 and using Unicode characters
higher than 127 (or 0). The number of UTF-8 bytes where counted instead of the number of characters.
<li>
The catalog name is now uppercase, to conform the JDBC standard for DatabaseMetaData.storesUpperCaseIdentifiers().
<li>
Creating or opening a small encrypted database is now a lot faster.
<li>
New functions FORMATDATETIME and PARSEDATETIME.
<li>
New XML encoding functions (XMLATTR, XMLNODE, XMLCOMMENT, XMLCDATA, XMLSTARTDOC, XMLTEXT).
<li>
Performance: improved opening of a large databases (about 3 times faster now for 500 MB databases).
<li>
Documented ALTER TABLE DROP COLUMN. The functionality was there already, but the documentation not.
</ul>
<h3>Version 0.9 / 2006-06-02</h3><ul>
<li>
Removed the GCJ h2-server.exe from download. It was not stable on Windows.
<li>
Issue #109: ALTER TABLE ADD COLUMN can make the database unusable if the original table contained a IDENTITY column.
<li>
New option to disable automatic closing of a database when the virtual machine exits.
Database URL: jdbc:h2:test;db_close_on_exit=false
<li>
New event: DatabaseEventListener.closingDatabase() is called before closing the database.
<li>
Connection.getCatalog() now returns the database name (CALL DATABASE()).
This name is also used in all system tables and DatabaseMetaData calls where applicable.
<li>
The function DATABASE() now return the short name of the database (without path),
and 'Unnamed' for anonymous in-memory databases.
<li>
Issue #108: There is a concurrency problem when multi threads access the same database at the same time,
and one is closing the connection and the other is executing CHECKPOINT at the exact the same time. Fixed.
<li>
Statements containing LIKE are now re-compiled when executed. Depending on the data,
an index on the column is used or not.
<li>
Issue# 107: When executing scripts that contained inserts with many columns, an OutOfMemory error could occur.
The problem was usage of shared Strings (String.substring). Now each String value is copied if required, releasing memory.
<li>
Issue #106: SET commands where not persisted if they where the first DDL commands for a connection. Fixed.
<li>
Issue #105: RUNSCRIPT (the command) didn't commit after each command if autocommit was on, therefore
large scripts run out of memory. Now it automatically commits.
<li>
Automatic starting of a web browser for Mac OS X should work now.
<li>
Starting the server is not a bit more intuitive. Just setting the -baseDir option for example will still start all servers.
By default, -tcp, -web, -browser and -odbc are started.
<li>
Issue #104: A HAVING condition on a column that was not in the GROUP BY list didn't work correctly in all cases. Fixed.
<li>
ORDER BY now uses an index if possible. Queries with LIMIT with ORDER BY are faster when the index can be used.
<li>
New option '-ifExists' for the TCP and ODBC server to disallow creating new databases remotely.
<li>
Shutdown of a TCP Server: Can now specifiy a password (tcpPassword). Passwords used at startup and
shutdown must match to shutdown. Uses a management database now for each server / port.
New option tcpShutdownForce (default is false) to kill the server without waiting for other connections to close.
<li>
Issue #103: Shutdown of a TCP Server from command line didn't always work.
</ul>
<h3>Version 0.9 / 2006-05-14</h3><ul>
<li>
New functions: CSVREAD and CSVWRITE to access CSV (comma separated values) files.
<li>
Locking: the synchronization was too restrictive, locking out the connection holding a lock
when another connection tried to lock the same object. Fixed.
<li>
Outer Join: currently, the table order of outer joins is kept, the tables are evaluated left to right
(with the exception of right outer join tables). This is a temporary solution only to solve problems
with join conditions.
<li>
Bugfix for SCRIPT: the rights where created before the objects. Fixed.
<li>
Implemented function LOCK_TIMEOUT().
<li>
Compatibility with DBPool: Support 'holdability' in the Connection methods (however the value it is currently ignored).
<li>
Connection.setTypeMap does not throw an exception any more if the type map is empty (null or 0 size).
<li>
Issue #102: INSTR('123456','34') should return 2.
<li>
Issue #101: A big result set with order by on a column or value that is not in the result list didn't work. Fixed.
<li>
Referential integrity: cascade didn't work for more than one level when it was self-referencing. Fixed.
<li>
New parameter charsetName in RunScript.execute.
New option CHARSET in the RUNSCRIPT command.
<li>
A backslash in the database URL (database name) didn't work, fixed. But a backslash in the settings part of the URL
is used as an escape for ';', that means database URLs of the form jdbc:h2:test;SETTING=a\;b\;c
are possible (but hopefully this is never required).
<li>
Added an interface SimpleRowSource so that an application / tool can create a dynamic result set
that produces rows on demand (for streaming result sets).
<li>
Foreign key constraints with different data types on the references / referencing column did not work. Fixed.
<li>
Fixed a problems that lead to a database (index file) corruption when killing the process.
Added a test case.
<li>
If a user has SELECT privileges for a view, he can now retrieve the data even if he does not have
privileges for the underlying table(s).
<li>
New system table INFORMATION_SCHEMA.CONSTRAINT that returns information about constraints
(mainly for check and unique constraints; for referential constraints see CROSS_REFERENCES).
<li>
Alter table alter column: the data type of a column could not be changed, and columns could not be dropped
if there was a constraint on the table. Now the data type can always be changed.
Alter table drop column: now the column can be dropped if it is not part of a constraint.
<li>
Views can now be 'invalid', for example if the table does not exist.
New synax CREATE FORCE VIEW.
New column STATUS (invalid / valid) in INFORMATION_SCHEMA.VIEWS table.
New SQL statement ALTER VIEW viewName RECOMPILE.
<li>
Issue #100: Altering a table with a self-referencing constraint didn't work. Fixed.
<li>
Support for IDENTITY(start, increment) as in CREATE TABLE TEST(ID BIGINT NOT NULL IDENTITY(10, 5));
<li>
Recovery did not always work correctly when the log file was switched.
Added tests for this use case.
<li>
Bugfix for CREATE ROLE IF NOT EXISTS X.
<li>
Removed support for LZMA. It was slow, and code coverage could not run.
If somebody needs this algorithm, it is better to add an open compression API.
<li>
Starting a server took 1 second before, now it takes only about 100 ms.
<li>
Server mode: If a parameter was not set in a prepared statement when using the server mode,
the connection to the server broke. Fixed.
<li>
Referential integrity: If there was a unique index with fewer columns than the foreign key on the child table,
it did not work. Fixed.
<li>
Javadoc / Doclet: ResultSet.getBytes was documented to return byte instead of byte[]. Fixed.
<li>
New setting RECOVER in the database URL (jdbc:h2:test;RECOVER=1) to open corrupted databases
(wrong checksum, corrupted index file or summary).
<li>
Bugfix: In server mode, big scrollable result sets didn't work. Fixed.
<li>
MERGE: instead of delete-insert, now use update-[insert]. This solves problems with foreign key constraints.
<li>
Bugfix for LIKE: A null pointer exception was thrown for WHERE NAME LIKE CAST(? AS VARCHAR).
<li>
Join optimization: expessions are now evaluated as early as possible, avoiding unnecessary lookups.
<li>
ResultSetMetaData.isAutoIncrement is implemented.
<li>
SCRIPT: STRINGENCODE instead of STRINGDECODE was used. The implementation
of STRINGDECODE was not correct for Unicode characters > 127. Fixed.
<li>
Documentation: [[NOT] NULL] instead of [NOT [NULL]]
<li>
Because of the REAL support, databases are not compatible with the old version.
Backup (with the old version), replace 'STRINGENCODE' in the script with
'STRINGDECODE', and restore is required to upgrade to the new version.
<li>
Support for REAL data type (Java 'float'; so far the DOUBLE type was used internallly).
</ul>
<h3>Version 0.9 / 2006-04-20</h3><ul>
<li>
Performance improvement for AND, OR, IFNULL, CASEWHEN, CASE, COALESCE and ARRAY_GET:
only the necessary parameters / operators are evaluated.
<li>
Bugfix for CASEWHEN: data type of return value was not evaluated, and this was a problem
when using prepared statements like this: WHERE CASEWHEN(ID<10, A, B)=?
<li>
New function DATABASE_PATH to retrieve the path and file name of a database.
<li>
Made the code more modular. New ant target: jarClient to compile the JDBC driver and the classes used
to remotely connect to a H2 server.
<li>
JdbcDataSourceFactory constructor is now public.
<li>
SET THROTTLE allows to throttle down the resource usage of a connection.
After each 50ms, the session sleeps for the specified amount of time.
<li>
ALTER TABLE ALTER COLUMN for a table that was referenced by another table didn't work. Fixed.
<li>
If index log is disabled (the default), indexe changes are flushed automatically each second
if the index was not changed. Like this index rebuilding is only required
(after a unexpected program termination, like power off) for indexes that
where recently changed.
<li>
Bugfix: ids of large objects (LOBs) are now correctly reserved when opening the database.
This improves the performance when using many LOBs.
<li>
Replaced log_index=1 with log=2. There are 3 log options now: 0 (disabled), 1 (default), and 2 (log index changes as well).
<li>
Got rid of the summary (.sum.db) file. The data is now stored in the log file instead.
<li>
If the application stopped without closing all connections (for example calling System.exit),
some committed transactions may have not been written to disk. Fixed.
<li>
Bugfix if index changes where logged (default is off): not all changes where logged, in some situations recovery would not work fast
(but no data loss as the indexes can be rebuilt; just slower database opening). Fixed.
<li>
DatabaseMetaData.getTypeInfo: compatibility with HSQLDB improved.
<li>
Parser: quoted keywords where not allowed as table or column names. Fixed.
<li>
An exception was thrown in FileStoreInputStream when reading 0 bytes. But this is allowed according to the specs.
<li>
Performance of LIMIT was slow when the result set was very big and the number of rows was small. Fixed
<li>
The RunScript tool (org.h2.tools.RunScript) now uses the same algorithm to parse scripts.
<li>
Bugfix: it was allowed to use jdbc:h2:test;database_event_listener=Test,
but only for the first connection. Now, the class name must be quoted in all cases:
jdbc:h2:test;database_event_listener='Test'
<li>
Implemented SET LOG 0 to disable logging for improved performance (about twice as fast).
<li>
Implemented TRUNCATE TABLE.
<li>
SCRIPT: New option 'DROP' to drop tables and views before creating them.
<li>
Chinese translation updates.
<li>
It was not possible to create views on system tables. Fixed.
<li>
If a database can't be opened because there is a bug in the startup information
(which is basically the SQL script of CREATE statements), then the database can now be opened
by specifying a database event listener.
<li>
Parser / MySQL compatibility: in the last release, for MySQL compatibility, this syntax was supported:
CREATE TABLE TEST(ID INT, INDEX(ID), KEY(ID));
But that means INDEX and KEY can't be used as column names.
Changed the parser so that this syntax is only supported in MySQL mode.
<li>
Optimizer: now chose a plan with index even if there are no or only a few rows in a table.
To avoid doing a table scan when no rows are in the table at prepare time, and many rows at execution time.
Using a row count offset of 1000.
<li>
MERGE: new SQL command to insert or update a row. Sometimes this is called UPSERT for UPdate or INSERT.
The grammar is a lot simpler than what Oracle supports.
<li>
SCRIPT: now the CREATE INDEX statements are after the INSERT statements, to improve performance.
<li>
Console: Bugfix for newline in a view definition.
<li>
Bugfix for CONCAT with more than 2 parameters.
</ul>
<h3>Version 0.9 / 2006-04-09</h3><ul>
<li>
Bugfix for VARCHAR_IGNORECASE.
<li>
Open database: Improved the performance for opening a database if it was not closed correctly before
(due to abnormal program termination or power failure).
<li>
Compact database: Added a sample application and documented how to do this.
<li>
Bugfix: the SCRIPT command created insert statements for views. Removed.
<li>
Implemented a way to shutdown a TCP server.
From command line, run: java org.h2.tools.Server -tcpShutdown tcp://localhost:9092
<li>
LOG_INDEX: new option in the database URL to log changes to the index file. This is allows fast recovery
from system crash for big databases. Sample URL: jdbc:h2:test;LOG_INDEX=1
<li>
Bugfix: using a low MAX_MEMORY_ROWS didn't work for GROUP BY queries with more groups. Fixed.
<li>
Improved the trigger API (provide a Connection to the Java function) and added a sample application.
<li>
Support setting parameters in the statement:
INSERT INTO TEST VALUES(?, ?) {1: 5000, 2: 'This is a test'}.
However, this feature is not documented yet as it's not clear if this is the final syntax.
Currently, used in the trace feature to create sql script files instead of Java class files
(in many cases, the classes just get too big and can't be compiled).
<li>
Support multiline statement in RUNSCRIPT.
<li>
Improved parser performance. Re-parsing of statements is avoided now if the database schema didn't change.
This should improve the performance for Hibernate, when many CREATE / DROP statements are executed.
<li>
Performance improvement for LIMIT when using simple queries without ORDER BY.
<li>
Improve compression ratio and performance for LZF.
<li>
Improve performance for Connection.getReadOnly() (Hibernate calls it a lot).
<li>
Server mode: Increased the socket buffer size to 64 KB. This should help performance
for medium size and bigger result sets. May thanks to James Devenish again!
<li>
Support for IPv6 addresses in JDBC URLs. RFC 2732 format is '[a:b:c:d:e:f:g:h]' or '[a:b:c:d:e:f:g:h]:port'.
May thanks to James Devenish
<li>
Bugfix for Linked Tables: The table definition was not stored correctly (with ''driver'' instead of 'driver' and so on). Fixed.
This was found by 'junheng'
<li>
Chinese localization of the H2 Console.
<li>
Bugfix: The connection was automatically closed sometimes when using a function with a connection parameter.
<li>
Bugfix in the Console: Auto-refresh of the object list for DROP / ALTER / CREATE statements, updatable result sets.
<li>
Improved support for MySQL syntax: ` is the same as ", except that the identifiers are converter to upper case.
Added support for special cases of MySQL CREATE TABLE syntax.
<li>
Java Functions: functions can now return ResultSet.
The SQL statement CALL GET_RESULT_SET(123)
then returns the result set created by the function.
Implemented a simple result set / result set meta data class that can be used
to create result sets in an application from scratch.
<li>
Web Server: the command line options where ignored. Fixed.
Renamed the options 'httpAllowOthers', 'httpPort', 'httpSSL' to 'web...'.
<li>
Oracle compatibility: CASE...END [CASE] (the last word is new).
Oracle compatibility: Date addition/subtraction: SYSDATE+1, (SYSDATE-1)-SYSDATE and so on.
Limited support for old Oracle outer join syntax (single column outer join, (+) must be on the far right).
This works:
CREATE TABLE Customers(CustomerID int); CREATE TABLE Orders(CustomerID int);
INSERT INTO Customers VALUES(1), (2), (3); INSERT INTO Orders VALUES(1), (3);
SELECT * FROM Customers LEFT OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;
SELECT * FROM Customers, Orders WHERE Customers.CustomerID = Orders.CustomerID(+);
</ul>
<h3>Version 0.9 / 2006-04-23</h3><ul>
<li>
Improved Hibernate Dialect for SQuirrel DB Copy.
<li>
Support for UPDATE TEST SET (column [,...])=(select | expr [,...]').
For Compiere compatibility.
<li>
Bugfixes for SCRIPT: write sequences before tables; write CLOB and BLOB data.
<li>
Added PolePosition benchmark results.
<li>
Bugfix in the server implementation: free up the memory. The new implementation does not rely on finalizers
any more. Removed finalizers, this improves the performance.
<li>
Implemented CROSS JOIN and NATURAL JOIN.
<li>
New keywords for join syntax: CROSS, NATURAL, FULL. However full outer join is not supported yet.
<li>
Improved documentation of the tools (Server port and so on).
<li>
The schema name of constraints is now automatically set to the table.
<li>
Compatibility for Derby style column level constraints.
<li>
New command ANALYZE to update the selectivity statistics.
New command ALTER TABLE ALTER COLUMN SELECTIVITY to manually set the selectivity of a column.
<li>
Allow a java.sql.Connection parameter in the Java function (as in HSQLDB).
<li>
Optimizer improvements.
<li>
Implemented SET DB_CLOSE_DELAY numberOfSeconds to be able to delay, or disable
(-1) closing the database. Default is still 0 (close database when closing the last connection).
<li>
After finding that HSQLDB was faster in the PolePosition test, and unsuccessful tries to
improve the performance of H2 even more, the reason is finally found: H2 always closed
the database when closing the last connection, but HSQLDB leaves the database open.
This also explains OutOfMemory problems when testing multiple databases with PolePosition.
But leaving the database open is a useful feature for some applications.
<li>
New system table CROSS_REFERENCES.
Implemented DatabaseMetaData.getImportedKeys, getExportedKeys, getCrossReferences.
<li>
Performance improvements in the binary tree and other places.
<li>
A new aggregate function SELECTIVITY is implemented. It calculates the selectivity of a column
by counting the distinct rows, but only up to 10000 values are kept in memory.
SELECT SELECTIVITY(ID), SELECTIVITY(NAME) FROM TEST LIMIT 1 SAMPLE_SIZE 10000 scans only 10000 rows.
<li>
A new option SAMPLE_SIZE is added to the LIMIT clause to specify the number of rows to scan for a aggregated
query.
<li>
Bugfixes for temporary tables. Implemented ON COMMIT DROP / DELETE ROWS, but
not documented because it is only here for compatibility, and I would advise against using it
because it is not available in most databases.
<li>
Improved parser performance and memory usage.
</ul>
<h3>Version 0.9 / 2006-03-08</h3><ul>
<li>
Bugfix for table level locking. Sometimes a Java-level deadlock occured when a connection was not closed.
<li>
Implemented the SHUTDOWN statement to close the database.
<li>
CURRENT_TIMESTAMP now also supports an optional precision argument.
<li>
Web Console: Improved support for MySQL, PostgreSQL, HSQLDB.
<li>
Automatically create the directory if it does not exist when creating a database.
<li>
Optimization for constant temporary views as in
SELECT SUM(B.X+A.X) FROM SYSTEM_RANGE(1, 10000) B,
(SELECT SUM(X) X FROM SYSTEM_RANGE(1, 10000)) A
<li>
Implemented the aggregate functions STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP. Implemented AVG(DISTINCT...).
<li>
Implemented GROUP_CONCAT. Similar to XMLAGG, but can be used for other text data (CSV, JSON) as well.
<li>
Fix for file_lock. The documentation and implementation did not match, and
the sleep gap was done even when using socket locking, making file locking with sockets
slower than required.
<li>
Security (TCP and ODBC Server): Connections made from other computers are now not allowed by default for security reasons.
This feature already existed for the web server.
Added two new settings (tcpAllowOthers and odbcAllowOthers)
<li>
Improved performance for queries in the server mode.
<li>
Improved the startup time for large databases using a 'summary' file.
The data in this file is redundant, but improves startup time.
<li>
Implemented a benchmark test suite for single connection performance test.
<li>
A primary key is now created automatically for identity / autoincrement columns.
<li>
SET ASSERT, a new setting to switch off assertions.
<li>
Hibernate dialect for Hibernate 3.1.
<li>
A new locking mode (level 2: table level locking with garbage collection).
</ul>
<h3>Version 0.9 / 2006-02-17</h3><ul>
<li>
The SQL syntax in the docs is now cross-linked
<li>
Written a parser for the BNF in the help file.
Written a test to run random statements based on this BNF.
<li>
Support function syntax: POSITION(pattern IN text).
<li>
Support for list syntax: select * from test where (id, name)=(1, 'Hi'). This is experimental only.
It should only be used for compatibility, as indexes are not used in this case currently.
This is currently undocumented, until indexes are used.
<li>
Function CONCAT now supports a variable number of arguments.
<li>
Support for MySQL syntax: LAST_INSERT_ID() as an alias for IDENTITY()
<li>
Support for Oracle syntax: DUAL table, sequence.NEXTVAL / CURRVAL.
Function NVL as alias for COALESCE.
Function INSTR as alias for LOCATE. Support for SYSTIMESTAMP and SYSTIME.
Function ROWNUM
<li>
Implemented a ROWNUM() function, but only supported for simple queries.
<li>
Implemented local temporary tables.
<li>
Implemented short version of constraints in CREATE TABLE:
CREATE TABLE TEST(ID INT UNIQUE, NAME VARCHAR CHECK LENGTH(NAME)>3).
<li>
Implemented function NEXTVAL and CURRVAL for sequences (PostgreSQL compatibility).
<li>
Bugfix for special cases of subqueries containing group by.
<li>
Multi-dimension (spatial index) support: This is done without supporting R-Tree indexes.
Instead, a function to map multi-dimensional data to a scalar (using a space filling curve) is implemented.
<li>
Computed Columns: Support for MS SQL Server style computed columns. with computed columns,
it is very simple to emulate functional indexes (sometimes called function-based indexes).
<li>
Locking: Added the SQL statement SET LOCK_MODE to disable table level locking.
This is to improve compatibility with HSQLDB.
<li>
Schema / Catalog: Improved compatibility with HSQLDB, now use a default schema called 'PUBLIC'.
</ul>
<h3>Version 0.9 / 2006-02-05</h3><ul>
<li>
Implemented function EXTRACT
<li>
Parser: bugfix for reading numbers like 1e-1
<li>
BLOB/CLOB: implemented Blob and Clob classes with 'read' functionality.
<li>
Function TRIM: other characters than space can be removed now.
<li>
Implemented CASE WHEN, ANY, ALL
<li>
Referential integrity: Deleting rows in the parent table was sometimes not possible, fixed.
<li>
Data compression: Implemented data compressions functions.
<li>
Large database: the database size was limited to 2 GB due to a bug. Fixed.
Improved the recovery performance. Added a progress function to the database event listener.
Renamed exception listener to database event listener. Added functionality to set
the listener at startup (to display the progress of opening / recovering a database).
<li>
Quoted keywords as identifiers: It was not possible to connect to the database again when
a (quoted) keyword was used as a table / column name. Fixed.
<li>
Compatibility: DATE, TIME and TIMESTAMP can now be used as identifiers (for example, table and column names).
They are only keywords if followed by a string, like in TIME '10:20:40'.
<li>
Compatibility: PostgreSQL and MySQL round 0.5 to 1 when converting to integer, HSQLDB and
other Java databases do not. Added this to the compatibility settings. The default is to behave like HSQLDB.
<li>
Synthetic tests: Utils / BitField threw java.lang.ArrayIndexOutOfBoundsException in some situations.
Parser: DATE / TIME / TIMESTAMP constants where not parser correctly in some situations.
Object ID assignment didn't always work correctly for indexes if other objects where dropped before.
Generated constraint names where not in all cases unique. If creating a unique index failed due to
primary key violation, some data remained in the database file, leading to problems later.
<li>
Storage: In some situations when creating many tables, the error 'double allocation' appeared. Fixed.
<li>
Auto-Increment column: It was possible to drop a sequence that belongs to a table
(auto increment column) after reconnecting. Fixed.
<li>
Auto-Increment column: It was possible to drop a sequence that belongs to a table
(auto increment column) after reconnecting. Fixed. ALTER TABLE ADD COLUMN didn't
work correctly on a table with auto-increment column,
<li>
Default values: If a subquery was used as a default value (do other database support this?),
it was executed in the wrong session context after reconnecting.
</ul>
<h3>Version 0.9 / 2006-01-26</h3><ul>
<li>
Autoincrement: There was a problem with IDENTITY columns, the inserted value was not stored in the session, and
so the IDENTITY() function didn't work after reconnect.
<li>
Storage: Simplified handling of deleted records. This also improves the performance of DROP TABLE.
<li>
Encrypted files: Fixed a bug with file.setLength if the new size is smaller than before.
<li>
Server mode: Fixed a problem with very big strings (larger than 64 KB).
<li>
Identity columns: when a manual value was inserted that was higher than the current
sequence value, the sequence was not updated to the higher value. Fixed.
<li>
Added a setting for the maximum number of rows (in a result set) that are kept in-memory
(MAX_MEMORY_ROWS). Increased the default from 1000 to 10000.
<li>
Bug: Sometimes log records where not written completely when using the binary storage format. Fixed.
<li>
Performance: now sorting the records by file position before writing.
This improves the performance of closing the database in some situations.
<li>
Two-Phase-Commit is implemented. However, the XA API is not yet implemented.
<li>
Bug: Recovery didn't work correctly if the database was not properly closed twice in a row
(reason: the checksum for rolled back records was not updated in the log file).
<li>
Bug: Renaming a table and then reconnect didn't work.
</ul>
<h3>Version 0.9 / 2006-01-17</h3><ul>
<li>
Referential integrity:
If the references columns are not specified, the primary key columns are used
(compatibility with PostgreSQL).
<li>
Durability:
A durability test has been implemented. Unfortunately, it is currently not
possible to guarantee transaction durability by default.
<li>
Bug in binary storage format:
If a record size was a multiple of 128 bytes, it was not saved correctly.
<li>
Multi-threaded kernel: Refactored the kernel to allow multiple threads running concurrently in the
same database. Disabled by default because more tests are required.
To enable it, set Constants.MULTI_THREADED_KERNEL to true.
<li>
Temporary tables are support now.
<li>
Exception Listener: Added functionality to deal with low disk space condition,
and support a callback feature so the application can notify somebody if a problem occurs.
<li>
Trigger: Added the Javadoc API to the docs.
<li>
DataSource: Implemented DataSource and DataSourceFactory.
Not sure in what context this will be used, but it's there now.
<li>
Parser: improved exception message (expected a, b, c,...) for some syntax errors.
</ul>
<h3>Version 0.9 / 2006-01-08</h3><ul>
<li>
Recovery: The database can now be opened if the index file is corrupt or does not exist.
<li>
Recovery: There was a bug in the power off test. Recovery was not tested correctly.
There was a case when recovery didn't work (so a database could not be opened).
Fixed.
Also fixed a problem with memory tables, they where not correctly persisted when using CHECKPOINT.
<li>
Commit: Implemented delaying the log file writing for performance reasons.
Most hard drives do not obey the fsync() function, so calling sync before each commit would not help.
See also 'Your Hard Drive Lies to You' http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252.
<li>
Tool: Create a new Recover tool.
<li>
Storage: support for URL parameter 'STORAGE' to support both text and binary storage formats.
The default is now binary mode storage.
<li>
Read-only database support. Added a function READONLY() and support for Connection.isReadOnly()
<li>
Functions: New functions UTF8TOSTRING, STRINGTOUTF8, HASH, ENCRYPT, DECRYPT, SECURE_RAND.
<li>
Translation: Started with French and Spanish translation of the Console.
Simplified the translation in this area (only one file needs to be translated now).
It would be great if somebody could help translating
(only around 100 words / sentences, file src/main/org/h2/web/_text_en.properties).
<li>
Storage: When a table was dropped, the space was not reused afterwards until all connections to this database
where closed. Now the space is reused without reopening the connection.
<li>
Large result set: max rows and offset didn't work with large result sets. Fixed.
<li>
New Settings: MAX_LOG_SIZE (automatic checkpoint) is implemented.
For compatibility with HSQLDB, SET LOGSIZE is supported as well.
<li>
Settings: TRACE_MAX_FILE_SIZE is now in MB instead of bytes, where 1 MB is 1024 * 1024 bytes.
</ul>
<h3>Version 0.9 / 2005-12-26</h3><ul>
<li>
GCJ: There seems to be a problem with synchronization with GCJ that is unproblematic with JDK.
If a method is synchronized, and exception occurs in this method, sometimes GCJ does not unlock
the object. One case has been fixed: when connecting to a database with the wrong user named locked
the object (probably the driver). One problem is still open: after the command
'create schema testsch authorization test', where the user test does not exists, locks something.
<li>
BTree: Fixed a critical bug in the btree update (keys where not compared when adding a record).
<li>
Binary data page: The length of a row was not always calculated correctly. Fixed and added a assertion.
(Binary data page is still disabled by default)
<li>
Linked tables: Sometimes the connection was not closed. Fixed.
<li>
Rights: Users with little access rights could not call ResultSet.getConcurrency.
They did not have rights for the metadata and system_range tables.
Now they can query those tables. The error message if there are not enough rights for an object was improved.
<li>
Rights: The table SYSTEM_INFORMATION.RIGHTS did not return the schema name for the granted table. Fixed.
<li>
Performance: a little bit of tuning was done, but currently switched off. In the future, the performance for simple things will be
comparable to HSQLDB (and H2 will be faster for complex queries). People who want to compare the performance of HSQLDB with H2
should switch DataPage.BINARY = true, Database.CHECK = false and LogSysetm.FLUSH_LOG_FOR_EACH_COMMIT = false
and compile the code again. Don't forget the compare the performance of opening and closing a database.
<li>
Memory usage: the index page cache size is now smaller to reduce the memory usage.
<li>
Storage: Truncating (dropping) a large table was very slow due to a bug. O(n^2). Fixed.
<li>
Log: Old (unused) log files where not correctly deleted at shutdown. This is now fixed.
</ul>
<h3>Version 0.9 / 2005-12-22</h3><ul>
<li>
Documentation: The Table of Contents in the PDF was broken (missing links, wrong page numbers).
Added documentation about trace options.
<li>
Version number: Added a build number, listed when calling DatabaseMetaData.getDatabaseProductVersion().
The console shows the product name and version.
<li>
Constraints: If adding a constraint created an index (automatically), then the order of operations was not logged correctly
(first the constraint and then the index, instead of first the index). Because of that, it was not possible to
connect to the database again. Fixed.
<li>
ResultSetMetaData.getColumn: Now return the column label as other databases (HSQLDB and MySQL) do.
<li>
Cache: A caching bug with medium to large databases (more than 16000 records) was fixed.
Too bad this was not found before releasing the database!
Also, a caching bug in linear hash index was fixed.
<li>
BigDecimal: There was an incompatibility with 'new BigDecimal(int)', which is not available in JDK 1.4.
It worked when the source code was compiled with JDK 1.4, but unfortunately it was compiled with JDK 1.5.
Now, 'new BigDecimal(String)' is always used to avoid this incompatibility.
<li>
Trace: Fix the output format, use 24 hour format instead of 12 hour format.
Enabling the trace option at runtime did not work as expected, this was fixed.
<li>
Tools: Added convenience methods in the tools (Backup, DeleteDbFiles,...) so they can be called
from another application more easily. Added Javadoc documentation.
<li>
Console: Stack traces are not thrown on the console window, to avoid blocking the application
if the user selects something in the console (in Windows).
<li>
Referential integrity: Supports the syntax where the referenced table is not specified.
In this case, the same table is referenced. (Compatibility with HSQLDB).
<li>
API Documentation: The 'throws' clause was not included in the Doclet. Fixed.
<li>
Tools: Added public 'execute' methods to simplify using the tools in other applications.
<li>
Clustering: The CreateCluster application now works even if both databases are on another machine.
<li>
Clustering: If autocommit is enabled on the client side, the commit on the server side is
executed after all servers executed the statement. This is slower, but fixed a theoretical
problem when using multiple connections (client A executes a statement, client B executes another
statement, and for some reason client B is faster and the statements of B are done on both
servers while client A is only done on the first server).
</ul>
<h3>Version 0.9 / 2005-12-13</h3><ul>
<li>
First public release.
</ul>
<br /><a name="roadmap"></a>
<h2>Roadmap</h2>
<h3>Highest Priority</h3>
<ul>
<li>Improve the documentation
<li>Add a migration guide (list differences between databases)
<li>Improve test code coverage
<li>More fuzz tests
<li>Test very large databases and LOBs (up to 256 GB)
<li>Test Multi-Threaded in-memory db access
</ul>
<h3>In Version 1.1</h3>
<ul>
<li>Change Constants.DEFAULT_MAX_MEMORY_UNDO to 10000 (and change the docs). Test.
<li>Enable and document optimizations, LOB files in directories
<li>Special methods for DataPage.writeByte / writeShort and so on
</ul>
<h3>Priority 1</h3>
<ul>
<li>More tests with MULTI_THREADED=1
<li>Test read committed transaction isolation
<li>Hot backup (incremental backup, online backup)
<li>Documentation (FAQ) for how to connect to H2
<li>Improve performance for create table (if this is possible)
<li>Test with Spatial DB in a box / JTS (http://docs.codehaus.org/display/GEOS/SpatialDBBox)
<li>Document how to use H2 with PHP
<li>Optimization: result set caching (like MySQL)
<li>Server side cursors
<li>Row level locking
<li>System table: open sessions and locks of a database
<li>System table: open connections and databases of a (TCP) server
<li>System table / function: cache usage
<li>Fix right outer joins
<li>Full outer joins
<li>Index organized tables: CREATE TABLE...(...) ORGANIZATION INDEX
<li>Long running queries / errors / trace system table.
<li>Migrate database tool (also from other database engines)
<li>Shutdown compact
<li>Optimization of distinct with index: select distinct name from test
<li>RECOVER=1 automatically if a problem opening
<li>Performance Test: executed statements must match, why sometimes a little more
<li>Forum: email notification doesn't work? test or disable or document
<li>Document server mode, embedded mode, web app mode, dual mode (server+embedded)
<li>Stop the server: close all open databases first
<li>Read-only databases inside a jar
<li>SET variable { TO | = } { value | 'value' | DEFAULT }
<li>Running totals: select @running:=if(@previous=t.ID,@running,0)+t.NUM as TOTAL, @previous:=t.ID
<li>Deleted LOB files after transaction is committed. Keep set of 'to be deleted' lobs files to the session (remove from the list on rollback)
<li>Support SET REFERENTIAL_INTEGRITY {TRUE|FALSE}
<li>Backup of BLOB / CLOB: use a stream for backup, use a block append function to restore.
</ul>
<h3>Priority 2</h3>
<ul>
<li>Support OSGi: http://oscar-osgi.sourceforge.net, http://incubator.apache.org/felix/index.html
<li>Connection pool manager
<li>Support VALUES(1), (2); SELECT * FROM (VALUES (1), (1), (1), (1), (2)) AS myTable (c1) (Derby)
<li>Optimization: automatic index creation suggestion using the trace file?
<li>Compression performance: don't allocate buffers, compress / expand in to out buffer
<li>Start / stop server with database URL
<li># is the start of a single line comment (MySQL) but date quote (Access). Mode specific
<li>Run benchmarks with JDK 1.5, Server
<li>Rebuild index functionality (other than delete the index file)
<li>Don't use deleteOnExit (bug 4513817: File.deleteOnExit consumes memory)
<li>Console: add accesskey to most important commands (A, AREA, BUTTON, INPUT, LABEL, LEGEND, TEXTAREA)
<li>Test hibernate slow startup? Derby faster? derby faster prepared statements?
<li>Feature: a setting to delete the the log or not (for backup)
<li>Test WithSun ASPE1_4; JEE Sun AS PE1.4
<li>Test performance again with SQL Server, Oracle, DB2
<li>Test with dbmonster (http://dbmonster.kernelpanic.pl/)
<li>Test with dbcopy (http://dbcopyplugin.sourceforge.net)
<li>Document how to view / scan a big trace file (less)
<li>Translation to spanish, chinese, japanese
<li>Set the database in an 'exclusive' mode
<li>Implement, test, document XAConnection and so on
<li>Web site: meta keywords, description, get rid of frame set
<li>Pluggable data type (for compression, validation, conversion, encryption)
<li>CHECK: find out what makes CHECK=TRUE slow, then: fast, nocheck, slow
<li>Improve recovery: improve code for log recovery problems (less try/catch)
<li>Log linear hash index changes, fast open / close
<li>Index usage for (ID, NAME)=(1, 'Hi'); document
<li>Faster hash function for strings, byte arrays, bigdecimal
<li>Suggestion: include jetty as Servlet Container (not AMP but JHJ)
<li>Trace shipping to server
<li>Performance / server mode: delay prepare? use UDP?
<li>Version check: javascript in the docs / web console and maybe in the library
<li>Aggregates: support MEDIAN
<li>Web server classloader: override findResource / getResourceFrom
<li>Cost for embedded temporary view is calculated wrong, if result is constant
<li>Comparison: pluggable sort order: natural sort
<li>Eclipse plugin
<li>iReport to support H2
<li>Implement CallableStatement
<li>Compression of the cache
<li>Run inside servlet
<li>Groovy Stored Procedures (http://groovy.codehaus.org/Groovy+SQL)
<li>Include SMPT (mail) server (at least client) (alert on cluster failure, low disk space,...)
<li>Make the jar more modular
<li>Document obfuscator usage
<li>Drop with restrict (currently cascade is the default)
<li>SCRIPT to pretty-print (at least Create Table)
<li>Document ConvertTraceToJava in javadoc and features
<li>Document limitation (line length) of find "**" test.trace.db > Trace.java
<li>Tiny XML parser (ignoring unneeded stuff)
<li>JSON parser
<li>Read only databases with log file (fast open with summary)
<li>Option for Java functions: 'constant' to allow early evaluation when all parameters are constant
<li>Improve trace option: add calendar, streams, objects,... try/catch
<li>Automatic collection of statistics (ANALYZE)
<li>Procedural language
<li>MVCC (Multi Version Cuncurrency Control)
<li>Maybe include JTidy. Check license
<li>Server: client ping from time to time (to avoid timeout - is timeout a problem?)
<li>Column level privileges
<li>Copy database: Tool with config GUI and batch mode, extendable (example: compare)
<li>Document shrinking jar file using http://proguard.sourceforge.net/
<li>Support SET TABLE DUAL READONLY;
<li>Don't write stack traces for common exceptions like duplicate key to the log by default
<li>Setting for MAX_QUERY_TIME (default no limit?)
<li>GCJ: is there a problem with updatable result sets?
<li>Convert large byte[]/Strings to streams in the JDBC API (asap).
<li>Use Janino to convert Java to C++
<li>Reduce disk space usage (Derby uses less disk space?)
<li>Fast conversion from LOB (stream) to byte array / String
<li>When converting to BLOB/CLOB (with setBytes / setString, or using SQL statement), use stream
<li>Support for user defined constants (to avoid using text or number literals; compile time safety)
<li>Events for: Database Startup, Connections, Login attempts, Disconnections, Prepare (after parsing), Web Server (see http://docs.openlinksw.com/virtuoso/fn_dbev_startup.html)
<li>Log compression
<li>Allow editing NULL values in the Console
<li>RunScript / RUNSCRIPT: progress meter and "suspend/resume" capability
<li>Compatibility: in MySQL, HSQLDB, /0.0 is NULL; in PostgreSQL, Derby: Division by zero
<li>Implement solution for long running transactions using user defined compensation statements
<li>Functional tables should accept parameters from other tables (see FunctionMultiReturn)
SELECT * FROM TEST T, P2C(T.A, T.R)
<li>Custom class loader to reload functions on demand
<li>Public CVS access
<li>Count index range query (count where id between 10 and 20)
<li>Test http://mysql-je.sourceforge.net/
<li>Close all files when closing the database (including LOB files that are open on the client side)
<li>Test Connection Pool http://jakarta.apache.org/commons/dbcp
<li>Should not print stack traces when killing the tests
<li>Implement Statement.cancel for server connections
<li>Should not throw a NullPointerException when closing the connection while an operation is running (TestCases.testDisconnect)
<li>Profiler option or profiling tool to find long running and often repeated queries
<li>Function to read/write a file from/to LOB
<li>Allow custom settings (@PATH for RUNSCRIPT for example)
<li>RUNSCRIPT: SET SCRIPT_PATH or similar to be used by RUNSCRIPT (and maybe SCRIPT)
<li>Performance test: read the data (getString) and use column names to get the data
<li>EXE file: maybe use http://jsmooth.sourceforge.net
<li>System Tray: http://jroller.com/page/stritti?entry=system_tray_implementations_for_java
<li>Test with GCJ: http://javacompiler.mtsystems.ch/
<li>SELECT ... FOR READ WAIT [maxMillisToWait]
<li>Automatically delete the index file if opening it fails
<li>Performance: Automatically build in-memory indexes if the whole table is in memory
<li>H2 Console: The webclient could support more features like phpMyAdmin.
<li>The HELP information schema can be directly exposed in the Console
<li>Maybe use the 0x1234 notation for binary fields, see MS SQL Server
<li>KEY_COLUMN_USAGE (http://dev.mysql.com/doc/refman/5.0/en/information-schema.html, http://www.xcdsql.org/Misc/INFORMATION_SCHEMA%20With%20Rolenames.gif)
<li>Support Oracle CONNECT BY in some way: http://www.adp-gmbh.ch/ora/sql/connect_by.html, http://philip.greenspun.com/sql/trees.html
<li>Support a property isDeterministic for Java functions
<li>SQL 2003 (http://www.wiscorp.com/sql_2003_standard.zip)
<li>http://www.jpackage.org
<li>Replace deleteOnExit with a weak reference map, or a simple loop on exit
<li>Version column (number/sequence and timestamp based)
<li>Optimize getGeneratedKey: (include last identity after each execute).
<li>Clustering: recovery needs to becomes fully automatic.
<li>Date: default date is '1970-01-01' (is it 1900-01-01 in the standard / other databases?)
<li>Test and document UPDATE TEST SET (ID, NAME) = (SELECT ID*10, NAME || '!' FROM TEST T WHERE T.ID=TEST.ID);
<li>Document EXISTS and so on, provide more samples.
<li>Modular build (multiple independent jars).
<li>Better space re-use in the files after deleting data (shrink the files)
<li>Max memory rows / max undo log size: use block count / row size not row count
<li>Index summary is only written if log=2; maybe write it also when log=1 and everything is fine (and no in doubt transactions)
<li>Support 123L syntax as in Java; example: SELECT (2000000000*2)
<li>Better support large transactions, large updates / deletes: allow tables without primary key
<li>Implement point-in-time recovery
<li>Memory database: add a feature to keep named database open until 'shutdown'
<li>Harden against 'out of memory attacks' (multi-threading, out of memory in the application)
<li>Use the directory of the first script as the default directory for any scripts run inside that script
<li>Include the version name in the jar file name
<li>Optimize IN(...), IN(select), ID=? OR ID=?: create temp table and use join
<li>Set Default Schema (SET search_path TO foo, ALTER USER test SET search_path TO bar,foo)
<li>LIKE: improved version for larger texts (currently using naive search)
<li>LOBs: support streaming for SCRIPT / RUNSCRIPT
<li>Auto-reconnect on lost connection to server (even if the server was re-started) except if autocommit was off and there was pending transaction
<li>LOBs: support streaming in server mode and cluster mode, and when using PreparedStatement.set with large values
<li>Backup / Restore of BLOBs needs to be improved
<li>The Backup tool should work with other databases as well
<li>Deferred integrity checking (DEFERRABLE INITIALLY DEFERRED)
<li>Automatically convert to the next 'higher' data type whenever there is an overflow.
<li>Throw an exception is thrown when the application calls getInt on a Long.
<li>Default date format for input and output (local date constants)
<li>Cache collation keys for performance
<li>Convert OR condition to UNION or IN if possible
<li>ValueInt.convertToString and so on (remove Value.convertTo)
<li>Support custom Collators
<li>Document ROWNUM usage for reports: SELECT ROWNUM, * FROM (subquery)
<li>Clustering: Reads should be randomly distributed or to a designated database on RAM
<li>Clustering: When a database is back alive, automatically synchronize with the master
<li>Standalone tool to get relevant system properties and add it to the trace output.
<li>Support mixed clustering mode (one embedded, the other server mode)
<li>Support 'call rpcname($1=somevalue)' (PostgreSQL, Oracle)
<li>HSQLDB compatibility: "INSERT INTO TEST(name) VALUES(?); SELECT IDENTITY()"
<li>Shutdown lock (shutdown can only start if there are no logins pending, and logins are delayed until shutdown ends)
<li>Automatically delete the index file if opening it fails
<li>DbAdapters http://incubator.apache.org/cayenne/
<li>JAMon (proxy jdbc driver)
<li>Console: Allow setting Null value; Alternative display format two column (for copy and paste as well)
<li>Console: Improve editing data (Tab, Shift-Tab, Enter, Up, Down, Shift+Del?)
<li>Console: Autocomplete Ctrl+Space inserts template
<li>Console: SQL statement formatter (newline before FROM, join, WHERE, AND, GROUP, ORDER, SELECT)
<li>Google Code http://code.google.com/p/h2database/issues/list#
<li>Simplify translation ('Donate a translation')
<li>Option to encrypt .trace.db file
<li>Write Behind Cache on SATA leads to data corruption
See also http://sr5tech.com/write_back_cache_experiments.htm
and http://www.jasonbrome.com/blog/archives/2004/04/03/writecache_enabled.html
<li>Support home directory as ~ in database URL (jdbc:h2:file:~/.mydir/myDB)
<li>Functions with unknown return or parameter data types: serialize / deserialize
<li>Test if idle TCP connections are closed, and how to disable that
<li>Compare with Daffodil One$DB
<li>Try using a factory for Row, Value[] (faster?), http://javolution.org/, alternative ObjectArray / IntArray
<li>Auto-Update feature
<li>ResultSet SimpleResultSet.readFromURL(String url): id varchar, state varchar, released timestamp
<li>RANK() and DENSE_RANK(), Partition using OVER()
<li>ROW_NUMBER (not the same as ROWNUM)
<li>Partial indexing (see PostgreSQL)
<li>BUILD should fail if ant test fails
<li>http://rubyforge.org/projects/hypersonic/
<li>DbVisualizer profile for H2
<li>Add comparator (x === y) : (x = y or (x is null and y is null))
<li>Try to create trace file even for read only databases
<li>Add a sample application that runs the H2 unit test and writes the result to a file (so it can be included in the user app)
<li>Count on a column that can not be null would be optimized to COUNT(*)
<li>Table order: ALTER TABLE TEST ORDER BY NAME DESC (MySQL compatibility)
<li>Backup tool should work with other databases as well
<li>Console: -ifExists doesn't work for the console. Add a flag to disable other dbs
<li>Maybe use Fowler Noll Vo hash function
<li>Improved Full text search (update index real-time or in a lower priority thread) Update now, update every n where n could be never.
<li>Update in-place
<li>Check if 'FSUTIL behavior set disablelastaccess 1' improves the performance (fsutil behavior query disablelastaccess)
<li>Remove finally() (almost) everywhere
<li>Java static code analysis: http://pmd.sourceforge.net/
<li>Java static code analysis: http://www.eclipse.org/tptp/
<li>Java static code analysis: http://checkstyle.sourceforge.net/
<li>Compatiblity for CREATE SCHEMA AUTHORIZATION
<li>Implement Clob / Blob truncate and the remaining functionality
<li>Maybe close LOBs after closing connection
<li>Tree join functionality
<li>Support alter table add column if table has views defined
<li>Add multiple columns at the same time with ALTER TABLE .. ADD .. ADD ..
<li>Support trigger on the tables information_schema.tables and ...columns
<li>Add H2 to Gem (Ruby install system)
<li>API for functions / user tables
<li>Order conditions inside AND / OR to optimize the performance
<li>Support linked JCR tables
<li>Make sure H2 is supported by Execute Query: http://executequery.org/
<li>Read InputStream when executing, as late as possible (maybe only embedded mode). Problem with re-execute.
<li>Full text search: min word length; store word positions
<li>FTP Server: Implement a client to send / receive files to server (dir, get, put)
<li>FTP Server: Implement SFTP / FTPS
<li>Add an option to the SCRIPT command to generate only portable / standard SQL
<li>Test Dezign for Databases (http://www.datanamic.com)
<li>Fast library for parsing / formatting: http://javolution.org/
<li>Updatable Views (simple cases first)
<li>Improve create index performance
<li>Support ARRAY data type
<li>Implement more JDBC 4.0 features
<li>H2 Console: implement a servlet to allow simple web app integration
<li>Support CHAR data type (internally use VARCHAR, but report CHAR for JPox)
<li>Option to globally disable / enable referential integrity checks
<li>Support ISO 8601 timestamp / date / time with timezone
<li>Support TRANSFORM / PIVOT as in MS Access
<li>ALTER SEQUENCE ... RENAME TO ... (http://www.postgresql.org/docs/8.2/static/sql-altersequence.html)
<li>SELECT * FROM (VALUES (...), (...), ....) AS alias(f1, ...)
<li>Support updatable views with join on primary keys (to extend a table)
<li>File_Read / File_Store funktionen: FILE_STORE('test.sql', ?), FILE_READ('test.sql')
<li>Public interface for functions (not public static)
</ul>
<h3>Not Planned</h3>
<ul>
<li>HSQLDB (did) support this: select id i from test where i>0 (other databases don't)
<li>String.intern (so that Strings can be compared with ==) will not be used because some VMs have problems when used extensively
</ul>
</div></td></tr></table></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Installation
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Installation</h1>
<a href="#requirements">
Requirements</a><br />
<a href="#supported_platforms">
Supported Platforms</a><br />
<a href="#installing">
Installing the Software</a><br />
<a href="#directory_structure">
Directory Structure</a><br />
<br /><a name="requirements"></a>
<h2>Requirements</h2>
To run the database, the following software stack is known to work.
Compatible software works too, but this was not tested.
<ul>
<li>Windows XP
<li>Sun JDK Version 1.4
<li>Mozilla Firefox 1.5
</ul>
<br /><a name="supported_platforms"></a>
<h2>Supported Platforms</h2>
As this database is written in Java, it can be run on many different platforms.
It is tested with Java 1.4 and 1.5, but can also be compiled to native code using GCJ.
The source code does not use features of Java 1.5. Currently, the database is
developed and tested on Windows XP using the Sun JDKs, but probably it also
works in many other operating systems and using other Java runtime environments.
<br /><a name="installing"></a>
<h2>Installing the Software</h2>
To install the software, run the installer or unzip it to a directory of your choice.
<br /><a name="directory_structure"></a>
<h2>Directory Structure</h2>
<p>
After installing, you should get the following directory structure:
</p>
<table>
<tr>
<th>Directory</th>
<th>Contents</th>
<tr>
<td>bin</td>
<td>Executables and JAR files</td>
</tr>
<tr>
<td>docs</td>
<td>Documentation</td>
</tr>
<tr>
<td>docs/html</td>
<td>HTML pages</td>
</tr>
<tr>
<td>docs/javadoc</td>
<td>Javadoc files</td>
</tr>
<tr>
<td>odbc</td>
<td>ODBC drivers and tools</td>
</tr>
<tr>
<td>src</td>
<td>Source files</td>
</tr>
</table>
</div></td></tr></table></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
License
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>License</h1>
<h2>Summary and License FAQ</h2>
This license is a modified version of the MPL 1.1 available at <a href="http://www.mozilla.org/MPL">www.mozilla.org/MPL</a>,
the changes are <u>underlined</u>.
There is a License FAQ section at the Mozilla web site, most of that is applicable to the H2 License as well.
<ul>
<li>You can use H2 for free. You can integrate it into your application (including commercial applications), and you can distribute it.
<li>Files containing only your code are not covered by this license (it is 'commercial friendly').
<li>Modifications to the H2 source code must be published.
<li>You don't need to provide the source code of H2 if you did not modify anything.
</ul>
However, nobody is allowed to rename H2, modify it a little, and sell it as a database engine without telling the customers it is in fact H2.
This happened to HSQLDB, when a company called 'bungisoft' copied HSQLDB, renamed it to 'RedBase', and tried to sell it,
hiding the fact that it was, in fact, just HSQLDB. At this time, it seems 'bungisoft' does not exist any more, but you can use the
Wayback Machine of http://www.archive.org and look for old web pages of http://www.bungisoft.com.
<p>
About porting the source code to another language (for example C# or C++): Converted source code (even if done manually) stays under the same
copyright and license as the original code. The copyright of the ported source code does not (automatically) go to the person ported the code.
<h2>H2 License, Version 1.0</h2>
<h3 id="section-1">1. Definitions</h3>
<p id="section-1.0.1"><b>1.0.1. "Commercial Use"</b>
means distribution or otherwise making the Covered Code available to a third party.
</p>
<p id="section-1.1"><b>1.1. "Contributor"</b>
means each entity that creates or contributes to the creation of Modifications.
</p>
<p id="section-1.2"><b>1.2. "Contributor Version"</b>
means the combination of the Original Code, prior Modifications used by a Contributor,
and the Modifications made by that particular Contributor.
</p>
<p id="section-1.3"><b>1.3. "Covered Code"</b>
means the Original Code or Modifications or the combination of the Original Code and
Modifications, in each case including portions thereof.
</p>
<p id="section-1.4"><b>1.4. "Electronic Distribution Mechanism"</b>
means a mechanism generally accepted in the software development community for the
electronic transfer of data.
</p>
<p id="section-1.5"><b>1.5. "Executable"</b>
means Covered Code in any form other than Source Code.
</p>
<p id="section-1.6"><b>1.6. "Initial Developer"</b>
means the individual or entity identified as the Initial Developer in the Source Code
notice required by <a href="#exhibit-a">Exhibit A</a>.
</p>
<p id="section-1.7"><b>1.7. "Larger Work"</b>
means a work which combines Covered Code or portions thereof with code not governed
by the terms of this License.
</p>
<p id="section-1.8"><b>1.8. "License"</b>
means this document.
</p>
<p id="section-1.8.1"><b>1.8.1. "Licensable"</b>
means having the right to grant, to the maximum extent possible, whether at the
time of the initial grant or subsequently acquired, any and all of the rights
conveyed herein.
</p>
<p id="section-1.9"><b>1.9. "Modifications"</b>
means any addition to or deletion from the substance or structure of either the
Original Code or any previous Modifications. When Covered Code is released as a
series of files, a Modification is:
</p>
<ol type="a">
<li id="section-1.9-a">Any addition to or deletion from the contents of a file
containing Original Code or previous Modifications.
<li id="section-1.9-b">Any new file that contains any part of the Original Code or
previous Modifications.
</ol>
<p id="section-1.10"><b>1.10. "Original Code"</b>
means Source Code of computer software code which is described in the Source Code
notice required by <a href="#exhibit-a">Exhibit A</a> as Original Code, and which,
at the time of its release under this License is not already Covered Code governed
by this License.
</p>
<p id="section-1.10.1"><b>1.10.1. "Patent Claims"</b>
means any patent claim(s), now owned or hereafter acquired, including without
limitation, method, process, and apparatus claims, in any patent Licensable by
grantor.
</p>
<p id="section-1.11"><b>1.11. "Source Code"</b>
means the preferred form of the Covered Code for making modifications to it,
including all modules it contains, plus any associated interface definition files,
scripts used to control compilation and installation of an Executable, or source
code differential comparisons against either the Original Code or another well known,
available Covered Code of the Contributor's choice. The Source Code can be in a
compressed or archival form, provided the appropriate decompression or de-archiving
software is widely available for no charge.
</p>
<p id="section-1.12"><b>1.12. "You" (or "Your")</b>
means an individual or a legal entity exercising rights under, and complying with
all of the terms of, this License or a future version of this License issued under
<a href="#section-6.1">Section 6.1.</a> For legal entities, "You" includes any entity
which controls, is controlled by, or is under common control with You. For purposes of
this definition, "control" means (a) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or otherwise, or (b)
ownership of more than fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
</p>
<h3 id="section-2">2. Source Code License</h3>
<h4 id="section-2.1">2.1. The Initial Developer Grant</h4>
<p>The Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive
license, subject to third party intellectual property claims:
<ol type="a">
<li id="section-2.1-a">under intellectual property rights (other than patent or
trademark) Licensable by Initial Developer to use, reproduce, modify, display, perform,
sublicense and distribute the Original Code (or portions thereof) with or without
Modifications, and/or as part of a Larger Work; and
<li id="section-2.1-b">under Patents Claims infringed by the making, using or selling
of Original Code, to make, have made, use, practice, sell, and offer for sale, and/or
otherwise dispose of the Original Code (or portions thereof).
<li id="section-2.1-c">the licenses granted in this Section 2.1
(<a href="#section-2.1-a">a</a>) and (<a href="#section-2.1-b">b</a>) are effective on
the date Initial Developer first distributes Original Code under the terms of this
License.
<li id="section-2.1-d">Notwithstanding Section 2.1 (<a href="#section-2.1-b">b</a>)
above, no patent license is granted: 1) for code that You delete from the Original Code;
2) separate from the Original Code; or 3) for infringements caused by: i) the
modification of the Original Code or ii) the combination of the Original Code with other
software or devices.
</ol>
<h4 id="section-2.2">2.2. Contributor Grant</h4>
<p>Subject to third party intellectual property claims, each Contributor hereby grants You
a world-wide, royalty-free, non-exclusive license
<ol type="a">
<li id="section-2.2-a">under intellectual property rights (other than patent or trademark)
Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and
distribute the Modifications created by such Contributor (or portions thereof) either on
an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger
Work; and
<li id="section-2.2-b">under Patent Claims infringed by the making, using, or selling of
Modifications made by that Contributor either alone and/or in combination with its
Contributor Version (or portions of such combination), to make, use, sell, offer for
sale, have made, and/or otherwise dispose of: 1) Modifications made by that Contributor
(or portions thereof); and 2) the combination of Modifications made by that Contributor
with its Contributor Version (or portions of such combination).
<li id="section-2.2-c">the licenses granted in Sections 2.2
(<a href="#section-2.2-a">a</a>) and 2.2 (<a href="#section-2.2-b">b</a>) are effective
on the date Contributor first makes Commercial Use of the Covered Code.
<li id="section-2.2-d">Notwithstanding Section 2.2 (<a href="#section-2.2-b">b</a>)
above, no patent license is granted: 1) for any code that Contributor has deleted from
the Contributor Version; 2) separate from the Contributor Version; 3) for infringements
caused by: i) third party modifications of Contributor Version or ii) the combination of
Modifications made by that Contributor with other software (except as part of the
Contributor Version) or other devices; or 4) under Patent Claims infringed by Covered Code
in the absence of Modifications made by that Contributor.
</ol>
<h3 id="section-3">3. Distribution Obligations</h3>
<h4 id="section-3.1">3.1. Application of License</h4>
<p>The Modifications which You create or to which You contribute are governed by the terms
of this License, including without limitation Section <a href="#section-2.2">2.2</a>. The
Source Code version of Covered Code may be distributed only under the terms of this License
or a future version of this License released under Section <a href="#section-6.1">6.1</a>,
and You must include a copy of this License with every copy of the Source Code You
distribute. You may not offer or impose any terms on any Source Code version that alters or
restricts the applicable version of this License or the recipients' rights hereunder.
However, You may include an additional document offering the additional rights described in
Section <a href="#section-3.5">3.5</a>.
<h4 id="section-3.2">3.2. Availability of Source Code</h4>
<p>Any Modification which You create or to which You contribute must be made available in
Source Code form under the terms of this License either on the same media as an Executable
version or via an accepted Electronic Distribution Mechanism to anyone to whom you made an
Executable version available; and if made available via Electronic Distribution Mechanism,
must remain available for at least twelve (12) months after the date it initially became
available, or at least six (6) months after a subsequent version of that particular
Modification has been made available to such recipients. You are responsible for ensuring
that the Source Code version remains available even if the Electronic Distribution
Mechanism is maintained by a third party.
<h4 id="section-3.3">3.3. Description of Modifications</h4>
<p>You must cause all Covered Code to which You contribute to contain a file documenting the
changes You made to create that Covered Code and the date of any change. You must include a
prominent statement that the Modification is derived, directly or indirectly, from Original
Code provided by the Initial Developer and including the name of the Initial Developer in
(a) the Source Code, and (b) in any notice in an Executable version or related documentation
in which You describe the origin or ownership of the Covered Code.
<h4 id="section-3.4">3.4. Intellectual Property Matters</h4>
<ol type="a">
<li id="section-3.4-a"><b>Third Party Claims:</b>
If Contributor has knowledge that a license under a third party's intellectual property
rights is required to exercise the rights granted by such Contributor under Sections
<a href="#section-2.1">2.1</a> or <a href="#section-2.2">2.2</a>, Contributor must include a
text file with the Source Code distribution titled "LEGAL" which describes the claim and the
party making the claim in sufficient detail that a recipient will know whom to contact. If
Contributor obtains such knowledge after the Modification is made available as described in
Section <a href="#section-3.2">3.2</a>, Contributor shall promptly modify the LEGAL file in
all copies Contributor makes available thereafter and shall take other steps (such as
notifying appropriate mailing lists or newsgroups) reasonably calculated to inform those who
received the Covered Code that new knowledge has been obtained.
<li id="section-3.4-b"><b>Contributor APIs:</b>
If Contributor's Modifications include an application programming interface and Contributor
has knowledge of patent licenses which are reasonably necessary to implement that
API, Contributor must also include this information in the legal file.
<li id="section-3.4-c"><b>Representations:</b>
Contributor represents that, except as disclosed pursuant to Section 3.4
(<a href="#section-3.4-a">a</a>) above, Contributor believes that Contributor's Modifications
are Contributor's original creation(s) and/or Contributor has sufficient rights to grant the
rights conveyed by this License.
</ol>
<h4 id="section-3.5">3.5. Required Notices</h4>
<p>You must duplicate the notice in <a href="#exhibit-a">Exhibit A</a> in each file of the
Source Code. If it is not possible to put such notice in a particular Source Code file due to
its structure, then You must include such notice in a location (such as a relevant directory)
where a user would be likely to look for such a notice. If You created one or more
Modification(s) You may add your name as a Contributor to the notice described in
<a href="#exhibit-a">Exhibit A</a>. You must also duplicate this License in any documentation
for the Source Code where You describe recipients' rights or ownership rights relating to
Covered Code. You may choose to offer, and to charge a fee for, warranty, support, indemnity
or liability obligations to one or more recipients of Covered Code. However, You may do so
only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You
must make it absolutely clear than any such warranty, support, indemnity or liability
obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer
and every Contributor for any liability incurred by the Initial Developer or such Contributor
as a result of warranty, support, indemnity or liability terms You offer.
<h4 id="section-3.6">3.6. Distribution of Executable Versions</h4>
<p>You may distribute Covered Code in Executable form only if the requirements of Sections
<a href="#section-3.1">3.1</a>, <a href="#section-3.2">3.2</a>,
<a href="#section-3.3">3.3</a>, <a href="#section-3.4">3.4</a> and
<a href="#section-3.5">3.5</a> have been met for that Covered Code, and if You include a
notice stating that the Source Code version of the Covered Code is available under the terms
of this License, including a description of how and where You have fulfilled the obligations
of Section <a href="#section-3.2">3.2</a>. The notice must be conspicuously included in any
notice in an Executable version, related documentation or collateral in which You describe
recipients' rights relating to the Covered Code. You may distribute the Executable version of
Covered Code or ownership rights under a license of Your choice, which may contain terms
different from this License, provided that You are in compliance with the terms of this
License and that the license for the Executable version does not attempt to limit or alter the
recipient's rights in the Source Code version from the rights set forth in this License. If
You distribute the Executable version under a different license You must make it absolutely
clear that any terms which differ from this License are offered by You alone, not by the
Initial Developer or any Contributor. You hereby agree to indemnify the Initial Developer and
every Contributor for any liability incurred by the Initial Developer or such Contributor as
a result of any such terms You offer.
<h4 id="section-3.7">3.7. Larger Works</h4>
<p>You may create a Larger Work by combining Covered Code with other code not governed by the
terms of this License and distribute the Larger Work as a single product. In such a case,
You must make sure the requirements of this License are fulfilled for the Covered Code.
<h3 id="section-4">4. Inability to Comply Due to Statute or Regulation.</h3>
<p>If it is impossible for You to comply with any of the terms of this License with respect to
some or all of the Covered Code due to statute, judicial order, or regulation then You must:
(a) comply with the terms of this License to the maximum extent possible; and (b) describe
the limitations and the code they affect. Such description must be included in the
<strong class="very-strong">legal</strong> file described in Section
<a href="#section-3.4">3.4</a> and must be included with all distributions of the Source Code.
Except to the extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to understand it.
<h3 id="section-5">5. Application of this License.</h3>
<p>This License applies to code to which the Initial Developer has attached the notice in
<a href="#exhibit-a">Exhibit A</a> and to related Covered Code.
<h3 id="section-6">6. Versions of the License.</h3>
<h4 id="section-6.1">6.1. New Versions</h4>
<p>The <u>H2 Group</u> may publish revised and/or new versions
of the License from time to time. Each version will be given a distinguishing version number.
<h4 id="section-6.2">6.2. Effect of New Versions</h4>
<p>Once Covered Code has been published under a particular version of the License, You may
always continue to use it under the terms of that version. You may also choose to use such
Covered Code under the terms of any subsequent version of the License published by the <u>H2 Group</u>.
No one other than the <u>H2 Group</u> has the right to modify the terms applicable to Covered Code
created under this License.
<h4 id="section-6.3">6.3. Derivative Works</h4>
<p>If You create or use a modified version of this License (which you may only do in order to
apply it to code which is not already Covered Code governed by this License), You must (a)
rename Your license so that the phrases <u>"H2 Group", "H2"</u>
or any confusingly similar phrase do not appear in your license (except to note that
your license differs from this License) and (b) otherwise make it clear that Your version of
the license contains terms which differ from the <u>H2 License</u>.
(Filling in the name of the Initial Developer, Original Code or Contributor in the
notice described in <a href="#exhibit-a">Exhibit A</a> shall not of themselves be deemed to
be modifications of this License.)
<h3 id="section-7">7. Disclaimer of Warranty</h3>
<p>Covered code is provided under this license on an "as is"
basis, without warranty of any kind, either expressed or implied, including, without
limitation, warranties that the covered code is free of defects, merchantable, fit for a
particular purpose or non-infringing. The entire risk as to the quality and performance of
the covered code is with you. Should any covered code prove defective in any respect, you
(not the initial developer or any other contributor) assume the cost of any necessary
servicing, repair or correction. This disclaimer of warranty constitutes an essential part
of this license. No use of any covered code is authorized hereunder except under this
disclaimer.
<h3 id="section-8">8. Termination</h3>
<p id="section-8.1">8.1. This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to cure such breach
within 30 days of becoming aware of the breach. All sublicenses to the Covered Code which
are properly granted shall survive any termination of this License. Provisions which, by
their nature, must remain in effect beyond the termination of this License shall survive.
<p id="section-8.2">8.2. If You initiate litigation by asserting a patent infringement
claim (excluding declaratory judgment actions) against Initial Developer or a Contributor
(the Initial Developer or Contributor against whom You file such action is referred to
as "Participant") alleging that:
<ol type="a">
<li id="section-8.2-a">such Participant's Contributor Version directly or indirectly
infringes any patent, then any and all rights granted by such Participant to You under
Sections <a href="#section-2.1">2.1</a> and/or <a href="#section-2.2">2.2</a> of this
License shall, upon 60 days notice from Participant terminate prospectively, unless if
within 60 days after receipt of notice You either: (i) agree in writing to pay
Participant a mutually agreeable reasonable royalty for Your past and future use of
Modifications made by such Participant, or (ii) withdraw Your litigation claim with
respect to the Contributor Version against such Participant. If within 60 days of
notice, a reasonable royalty and payment arrangement are not mutually agreed upon in
writing by the parties or the litigation claim is not withdrawn, the rights granted by
Participant to You under Sections <a href="#section-2.1">2.1</a> and/or
<a href="#section-2.2">2.2</a> automatically terminate at the expiration of the 60 day
notice period specified above.
<li id="section-8.2-b">any software, hardware, or device, other than such Participant's
Contributor Version, directly or indirectly infringes any patent, then any rights
granted to You by such Participant under Sections 2.1(<a href="#section-2.1-b">b</a>)
and 2.2(<a href="#section-2.2-b">b</a>) are revoked effective as of the date You first
made, used, sold, distributed, or had made, Modifications made by that Participant.
</ol>
<p id="section-8.3">8.3. If You assert a patent infringement claim against Participant
alleging that such Participant's Contributor Version directly or indirectly infringes
any patent where such claim is resolved (such as by license or settlement) prior to the
initiation of patent infringement litigation, then the reasonable value of the licenses
granted by such Participant under Sections <a href="#section-2.1">2.1</a> or
<a href="#section-2.2">2.2</a> shall be taken into account in determining the amount or
value of any payment or license.
<p id="section-8.4">8.4. In the event of termination under Sections
<a href="#section-8.1">8.1</a> or <a href="#section-8.2">8.2</a> above, all end user
license agreements (excluding distributors and resellers) which have been validly
granted by You or any distributor hereunder prior to termination shall survive
termination.
<h3 id="section-9">9. Limitation of Liability</h3>
<p>Under no circumstances and under no legal theory, whether
tort (including negligence), contract, or otherwise, shall you, the initial developer,
any other contributor, or any distributor of covered code, or any supplier of any of
such parties, be liable to any person for any indirect, special, incidental, or
consequential damages of any character including, without limitation, damages for loss
of goodwill, work stoppage, computer failure or malfunction, or any and all other
commercial damages or losses, even if such party shall have been informed of the
possibility of such damages. This limitation of liability shall not apply to liability
for death or personal injury resulting from such party's negligence to the extent
applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion
or limitation of incidental or consequential damages, so this exclusion and limitation
may not apply to you.
<h3 id="section-10">10. United States Government End Users</h3>
<p>The Covered Code is a "commercial item", as that term is defined in 48
C.F.R. 2.101 (October 1995), consisting of
"commercial computer software" and "commercial computer software documentation", as such
terms are used in 48 C.F.R. 12.212 (September 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R.
227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users
acquire Covered Code with only those rights set forth herein.
<h3 id="section-11">11. Miscellaneous</h3>
<p>This License represents the complete agreement concerning subject matter hereof. If
any provision of this License is held to be unenforceable, such provision shall be
reformed only to the extent necessary to make it enforceable. This License shall be
governed by <u>Swiss</u> law provisions (except to the extent applicable law, if any,
provides otherwise), excluding its conflict-of-law provisions. With respect to
disputes in which at least one party is a citizen of, or an entity chartered or
registered to do business in <u>Switzerland</u>, any litigation relating to
this License shall be subject to the jurisdiction of <u>Switzerland</u>,
with the losing party responsible for costs, including without limitation, court
costs and reasonable attorneys' fees and expenses. The application of the United
Nations Convention on Contracts for the International Sale of Goods is expressly
excluded. Any law or regulation which provides that the language of a contract
shall be construed against the drafter shall not apply to this License.
<h3 id="section-12">12. Responsibility for Claims</h3>
<p>As between Initial Developer and the Contributors, each party is responsible for
claims and damages arising, directly or indirectly, out of its utilization of rights
under this License and You agree to work with Initial Developer and Contributors to
distribute such responsibility on an equitable basis. Nothing herein is intended or
shall be deemed to constitute any admission of liability.
<h3 id="section-13">13. Multiple-Licensed Code</h3>
<p>Initial Developer may designate portions of the Covered Code as
"Multiple-Licensed". "Multiple-Licensed" means that the Initial Developer permits
you to utilize portions of the Covered Code under Your choice of this
or the alternative licenses, if any, specified by the Initial Developer in the file
described in <a href="#exhibit-a">Exhibit A</a>.
<h3 id="exhibit-a">Exhibit A</h3>
<pre>
Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
</pre>
</div></td></tr></table></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
H2 Database Engine
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>H2 Database Engine</h1>
Welcome to H2, the free SQL database engine.
<p>
<a href="quickstartText.html" style="font-size: 16px; font-weight: bold">Quickstart</a>
<br>
Click here to get a fast overview.
<br><br>
<a href="features.html" style="font-size: 16px; font-weight: bold">Features</a>
<br>
See what this database can do.
<br><br>
<a href="tutorial.html" style="font-size: 16px; font-weight: bold">Tutorial</a>
<br>
Go through the samples.
</div></td></tr></table></body></html>
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
*/
function loadFrameset() {
var a = location.search.split('&');
var page = decodeURIComponent(a[0].substr(1));
var frame = a[1];
if(page && frame){
var s = "top." + frame + ".location.replace('" + page + "')";
eval(s);
}
return;
}
function frameMe(frame) {
var frameset = "frame.html"; // name of the frameset page
if(frame == null) {
frame = 'main';
}
page = new String(self.document.location);
var pos = page.lastIndexOf("/") + 1;
var file = page.substr(pos);
file = encodeURIComponent(file);
if(window.name != frame) {
var s = frameset + "?" + file + "&" + frame;
top.location.replace(s);
} else {
highlight();
}
return;
}
function addHighlight(page, word, count) {
if(count > 0) {
if(top.main.document.location.href.indexOf(page) > 0 && top.main.document.body && top.main.document.body.innerHTML) {
highlight();
} else {
window.setTimeout('addHighlight("'+page+'","'+word+'",'+(count-1)+')', 10);
}
}
}
function highlight() {
var url = new String(top.main.location.href);
if(url.indexOf('?highlight=') < 0) {
return;
} else {
var page = url.split('?highlight=');
var word = decodeURIComponent(page[1]);
top.main.document.body.innerHTML = highlightSearchTerms(top.main.document.body, word);
top.main.location = '#firstFound';
// window.setTimeout('goFirstFound()', 1);
}
}
function goFirstFound() {
top.main.location = '#firstFound';
/*
var page = new String(parent.main.location);
alert('first: ' + page);
page = page.split('#')[0];
paramSplit = page.split('?');
page = paramSplit[0];
page += '#firstFound';
if(paramSplit.length > 0) {
page += '?' + paramSplit[1];
}
top.main.location = page;
*/
}
function highlightSearchTerms(body, searchText) {
matchColor = "ffff00,00ffff,00ff00,ff8080,ff0080".split(',');
highlightEndTag = "</span>";
searchArray = searchText.split(",");
if (!body || typeof(body.innerHTML) == "undefined") {
return false;
}
var bodyText = body.innerHTML;
for (var i = 0; i < searchArray.length; i++) {
var color = matchColor[i % matchColor.length];
highlightStartTag = "<span ";
if(i==0) {
highlightStartTag += "id=firstFound ";
}
highlightStartTag += "style='color:#000000; background-color:#"+color+";'>";
bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
}
return bodyText;
}
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) {
if(searchTerm == undefined || searchTerm=="") {
return bodyText;
}
var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();
while (bodyText.length > 0) {
i = lcBodyText.indexOf(lcSearchTerm, i+1);
if (i < 0) {
newText += bodyText;
bodyText = "";
} else {
// skip anything inside an HTML tag
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
// skip anything inside a <script> block
if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
bodyText = bodyText.substr(i + searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
}
}
}
}
return newText;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Performance
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Performance</h1>
<a href="#performance_comparison">
Performance Comparison</a><br />
<a href="#application_profiling">
Application Profiling</a><br />
<a href="#database_performance_tuning">
Performance Tuning</a><br />
<br /><a name="performance_comparison"></a>
<h2>Performance Comparison</h2>
In most cases H2 is a lot faster than all other
(open source and not open source) database engines:
<h3>Embedded</h3>
<table border="1" class="bar">
<tr><th>Test Case</th><th>Unit</th><th>H2</th><th>HSQLDB</th><th>Derby</th></tr>
<tr><td>Simple: Init</td><td>ms</td><td>234</td><td>219</td><td>4187</td></tr>
<tr><td>Simple: Query (random)</td><td>ms</td><td>188</td><td>140</td><td>1281</td></tr>
<tr><td>Simple: Query (sequential)</td><td>ms</td><td>156</td><td>125</td><td>1187</td></tr>
<tr><td>Simple: Update (random)</td><td>ms</td><td>344</td><td>594</td><td>7047</td></tr>
<tr><td>Simple: Delete (sequential)</td><td>ms</td><td>156</td><td>125</td><td>4203</td></tr>
<tr><td>Simple: Memory Usage</td><td>MB</td><td>3</td><td>6</td><td>6</td></tr>
<tr><td>BenchA: Init</td><td>ms</td><td>172</td><td>125</td><td>4812</td></tr>
<tr><td>BenchA: Transactions</td><td>ms</td><td>828</td><td>812</td><td>10282</td></tr>
<tr><td>BenchA: Memory Usage</td><td>MB</td><td>7</td><td>10</td><td>8</td></tr>
<tr><td>BenchC: Init</td><td>ms</td><td>734</td><td>296</td><td>9469</td></tr>
<tr><td>BenchC: Transactions</td><td>ms</td><td>1797</td><td>23782</td><td>10140</td></tr>
<tr><td>BenchC: Memory Usage</td><td>MB</td><td>10</td><td>16</td><td>8</td></tr>
<tr><td>Total Time</td><td>ms</td><td>4609</td><td>26218</td><td>52624</td></tr>
<tr><td>Statement per Second</td><td>#</td><td>34446</td><td>6055</td><td>3016</td></tr>
</table>
<h3>Client-Server</h3>
<table border="1" class="bar">
<tr><th>Test Case</th><th>Unit</th><th>H2</th><th>HSQLDB</th><th>Derby</th><th>PostgreSQL</th><th>MySQL</th></tr>
<tr><td>Simple: Init</td><td>ms</td><td>1157</td><td>1187</td><td>5688</td><td>2391</td><td>1547</td></tr>
<tr><td>Simple: Query (random)</td><td>ms</td><td>1312</td><td>1265</td><td>5406</td><td>2672</td><td>1578</td></tr>
<tr><td>Simple: Query (sequential)</td><td>ms</td><td>1266</td><td>1219</td><td>6203</td><td>2406</td><td>1578</td></tr>
<tr><td>Simple: Update (random)</td><td>ms</td><td>1375</td><td>1547</td><td>9328</td><td>2953</td><td>1844</td></tr>
<tr><td>Simple: Delete (sequential)</td><td>ms</td><td>515</td><td>578</td><td>4688</td><td>1235</td><td>859</td></tr>
<tr><td>Simple: Memory Usage</td><td>MB</td><td>4</td><td>7</td><td>6</td><td>0</td><td>0</td></tr>
<tr><td>BenchA: Init</td><td>ms</td><td>610</td><td>547</td><td>5781</td><td>1454</td><td>1063</td></tr>
<tr><td>BenchA: Transactions</td><td>ms</td><td>3203</td><td>3453</td><td>14515</td><td>6625</td><td>4015</td></tr>
<tr><td>BenchA: Memory Usage</td><td>MB</td><td>7</td><td>11</td><td>9</td><td>0</td><td>0</td></tr>
<tr><td>BenchC: Init</td><td>ms</td><td>1218</td><td>782</td><td>10922</td><td>1796</td><td>2406</td></tr>
<tr><td>BenchC: Transactions</td><td>ms</td><td>5547</td><td>24343</td><td>17796</td><td>8313</td><td>5390</td></tr>
<tr><td>BenchC: Memory Usage</td><td>MB</td><td>10</td><td>16</td><td>10</td><td>0</td><td>1</td></tr>
<tr><td>Total Time</td><td>ms</td><td>16265</td><td>34921</td><td>80359</td><td>30189</td><td>20296</td></tr>
<tr><td>Statement per Second</td><td>#</td><td>9761</td><td>4546</td><td>1975</td><td>5259</td><td>7823</td></tr>
</table>
<h3>PolePosition Benchmark</h3>
<table border="1" class="bar">
<tr><th>Test Case</th><th>Unit</th><th>H2</th><th>HSQLDB</th><th>MySQL</th></tr>
<tr><td>Melbourne write</td><td>ms</td><td>369</td><td>249</td><td>2022</td></tr>
<tr><td>Melbourne read</td><td>ms</td><td>47</td><td>49</td><td>93</td></tr>
<tr><td>Melbourne read_hot</td><td>ms</td><td>24</td><td>43</td><td>95</td></tr>
<tr><td>Melbourne delete</td><td>ms</td><td>147</td><td>133</td><td>176</td></tr>
<tr><td>Sepang write</td><td>ms</td><td>965</td><td>1201</td><td>3213</td></tr>
<tr><td>Sepang read</td><td>ms</td><td>765</td><td>948</td><td>3455</td></tr>
<tr><td>Sepang read_hot</td><td>ms</td><td>789</td><td>859</td><td>3563</td></tr>
<tr><td>Sepang delete</td><td>ms</td><td>1384</td><td>1596</td><td>6214</td></tr>
<tr><td>Bahrain write</td><td>ms</td><td>1186</td><td>1387</td><td>6904</td></tr>
<tr><td>Bahrain query_indexed_string</td><td>ms</td><td>336</td><td>170</td><td>693</td></tr>
<tr><td>Bahrain query_string</td><td>ms</td><td>18064</td><td>39703</td><td>41243</td></tr>
<tr><td>Bahrain query_indexed_int</td><td>ms</td><td>104</td><td>134</td><td>678</td></tr>
<tr><td>Bahrain update</td><td>ms</td><td>191</td><td>87</td><td>159</td></tr>
<tr><td>Bahrain delete</td><td>ms</td><td>1215</td><td>729</td><td>6812</td></tr>
<tr><td>Imola retrieve</td><td>ms</td><td>198</td><td>194</td><td>4036</td></tr>
<tr><td>Barcelona write</td><td>ms</td><td>413</td><td>832</td><td>3191</td></tr>
<tr><td>Barcelona read</td><td>ms</td><td>119</td><td>160</td><td>1177</td></tr>
<tr><td>Barcelona query</td><td>ms</td><td>20</td><td>5169</td><td>101</td></tr>
<tr><td>Barcelona delete</td><td>ms</td><td>388</td><td>319</td><td>3287</td></tr>
<tr><td>Total</td><td>ms</td><td>26724</td><td>53962</td><td>87112</td></tr>
</table>
<h3>Benchmark Results and Comments</h3>
<h4>H2</h4>
Version 0.9 (2006-11-03) was used for the test.
For simpler operations, the performance of H2 is about the same as for HSQLDB.
For more complex queries, the query optimizer is very important.
However H2 is not very fast in every case, certain kind of queries may still be slow.
One situation where is H2 is slow is large result sets, because they are buffered to
disk if more than a certain number of records are returned.
The advantage of buffering is, there is no limit on the result set size.
The open/close time is almost fixed, because of the file locking protocol: The engine waits
20 ms after opening a database to ensure the database files are not opened by another process.
<h4>HSQLDB</h4>
Version 1.8.0.5 was used for the test.
HSQLDB is fast when using simple operations.
HSQLDB is very slow in the last test (BenchC: Transactions), probably because is has a bad query optimizer.
One query where HSQLDB is slow is a two-table join:
<pre>
SELECT COUNT(DISTINCT S_I_ID) FROM ORDER_LINE, STOCK
WHERE OL_W_ID=? AND OL_D_ID=? AND OL_O_ID&lt;? AND OL_O_ID>=?
AND S_W_ID=? AND S_I_ID=OL_I_ID AND S_QUANTITY&lt;?
</pre>
The PolePosition benchmark also shows that the query optimizer does not do a very good job for some queries.
A disadvantage in HSQLDB is the slow startup / shutdown time (currently not listed) when using bigger databases.
The reason is, a backup of the database is created whenever the database is opened or closed.
<h4>Derby</h4>
Version 10.2.1.6 was used for the test.
Derby is clearly the slowest embedded database in this test.
This seems to be a structural problem,
because all operations are really slow. It will not be easy for the developers of
Derby to improve the performance to a reasonable level.
<h4>PostgreSQL</h4>
Version 8.1.4 was used for the test.
The following options where changed in postgresql.conf:
fsync = off, commit_delay = 1000.
PostgreSQL is run in server mode. It looks like the base performance is slower than
MySQL, but the reason could be the network layer.
The memory usage number is incorrect, because only the memory usage of the JDBC driver is measured.
<h4>MySQL</h4>
Version 5.0.22 was used for the test.
MySQL was run with the InnoDB backend.
The setting innodb_flush_log_at_trx_commit
(found in the my.ini file) was set to 0. Otherwise (and by default), MySQL is really slow
(around 140 statements per second in this test) because it tries to flush the data to disk for each commit.
For small transactions (when autocommit is on) this is really slow.
But many use cases use small or relatively small transactions.
Too bad this setting is not listed in the configuration wizard,
and it always overwritten when using the wizard.
You need to change this setting manually in the file my.ini, and then restart the service.
The memory usage number is incorrect, because only the memory usage of the JDBC driver is measured.
<h4>Firebird</h4>
Firebird 1.5 (default installation) was tested, but the results are not published currently.
It is possible to run the performance test with the Firebird database,
and any information on how to configure Firebird for higher performance are welcome.
<h4>Why Oracle / MS SQL Server / DB2 are Not Listed</h4>
The license of these databases does not allow to publish benchmark results.
This doesn't mean that they are fast. They are in fact quite slow,
and need a lot of memory. But you will need to test this yourself.
SQLite was not tested because the JDBC driver doesn't support transactions.
<h3>About this Benchmark</h3>
<h4>Number of Connections</h4>
This is a single-connection benchmark.
<h4>Real-World Tests</h4>
Good benchmarks emulate real-world use cases. This benchmark includes 3 test cases:
A simple test case with one table and many small updates / deletes.
BenchA is similar to the TPC-A test, but single connection / single threaded (see also: www.tpc.org).
BenchC is similar to the TPC-C test, but single connection / single threaded.
<h4>Comparing Embedded with Server Databases</h4>
This is mainly a benchmark for embedded databases (where the application runs in the same
virtual machine than the database engine). However MySQL and PostgreSQL are not Java
databases and cannot be embedded into a Java application.
For the Java databases, both embedded and server modes are tested.
<h4>Test Platform</h4>
This test is run on Windows XP with the virus scanner switched off.
The VM used is Sun JDK 1.4.
<h4>Multiple Runs</h4>
When a Java benchmark is run first, the code is not fully compiled and
therefore runs slower than when running multiple times. A benchmark
should always run the same test multiple times and ignore the first run(s).
This benchmark runs three times, the last run counts.
<h4>Memory Usage</h4>
It is not enough to measure the time taken, the memory usage is important as well.
Performance can be improved in databases by using a bigger in-memory cache,
but there is only a limited amout of memory available on the system.
HSQLDB tables are kept fully in memory by default, this benchmark
uses 'disk based' tables for all databases.
Unfortunately, it is not so easy to calculate the memory usage of PostgreSQL
and MySQL, because they run in a different process than the test. This benchmark currently
does not print memory usage of those databases.
<h4>Delayed Operations</h4>
Some databases delay some operations (for example flushing the buffers)
until after the benchmark is run. This benchmark waits between
each database tested, and each database runs in a different process (sequentially).
<h4>Transaction Commit / Durability</h4>
Durability means transaction committed to the database will not be lost.
Some databases (for example MySQL) try to enforce this by default by calling fsync() to flush the buffers, but
most hard drives don't actually flush all data. Calling fsync() slows down transaction commit a lot,
but doesn't always make data durable. When comparing the results, it is important to
think about the effect. Many database suggest to 'batch' operations when possible.
This benchmark switches off autocommit when loading the data, and calls commit after each 1000
inserts. However many applications need 'short' transactions at runtime (a commit after each update).
This benchmark commits after each update / delete in the simple benchmark, and after each
business transaction in the other benchmarks.
<h4>Using Prepared Statements</h4>
Wherever possible, the test cases use prepared statements.
<h4>Currently Not Tested: Startup Time</h4>
The startup time of a database engine is important as well for embedded use.
This time is not measured currently.
Also, not tested is the time used to create a database and open an existing database.
Here, one (wrapper) connection is opened at the start,
and for each step a new connection is opened and then closed.
That means the Open/Close time listed is for opening a connection
if the database is already in use.
<br /><a name="application_profiling"></a>
<h2>Application Profiling</h2>
<h3>Analyze First</h3>
Before trying to optimize the performance, it is important to know where the time is actually spent.
The same is true for memory problems.
Premature or 'blind' optimization should be avoided, as it is not an efficient way to solve the problem.
There are various ways to analyze the application. In some situations it is possible to
compare two implementations and use System.currentTimeMillis() to find out which one is faster.
But this does not work for complex applications with many modules, and for memory problems.
A very good tool to measure both the memory and the CPU is the
<a href="http://www.yourkit.com">YourKit Java Profiler</a>. This tool is also used
to optimize the performance and memory footprint of this database engine.
<br /><a name="database_performance_tuning"></a>
<h2>Database Performance Tuning</h2>
<h3>Virus Scanners</h3>
Some virus scanners scan files every time they are accessed.
It is very important for performance that database files are not scanned for viruses.
The database engine does never interprets the data stored in the files as programs,
that means even if somebody would store a virus in a database file, this would
be harmless (when the virus does not run, it cannot spread).
Some virus scanners allow excluding file endings. Make sure files ending with .db are not scanned.
<h3>Using the Trace Options</h3>
If the main performance hot spots are in the database engine, in many cases the performance
can be optimized by creating additional indexes, or changing the schema. Sometimes the
application does not directly generate the SQL statements, for example if an O/R mapping tool
is used. To view the SQL statements and JDBC API calls, you can use the trace options.
For more information, see <a href="features.html#trace_options">Using the Trace Options</a>.
<h3>Index Usage</h3>
This database uses indexes to improve the performance of SELECT, UPDATE and DELETE statements.
If a column is used in the WHERE clause of a query, and if an index exists on this column,
then the index can be used. Multi-column indexes are used if all or the first columns of the index are used.
Both equality lookup and range scans are supported.
Indexes are not used to order result sets: The results are sorted in memory if required.
Indexes are created automatically for primary key and unique constraints.
Indexes are also created for foreign key constraints, if required.
For other columns, indexes need to be created manually using the CREATE INDEX statement.
<h3>Optimizer</h3>
This database uses a cost based optimizer. For simple and queries and queries with medium complexity
(less than 7 tables in the join), the expected cost (running time) of all possible plans is calculated,
and the plan with the lowest cost is used. For more complex queries, the algorithm first tries
all possible combinations for the first few tables, and the remaining tables added using a greedy algorithm
(this works well for most joins). Afterwards a genetic algorithm is used to test at most 2000 distinct plans.
Only left-deep plans are evaluated.
<h3>Expression Optimization</h3>
After the statement is parsed, all expressions are simplified automatically if possible. Operations
are evaluated only once if all parameters are constant. Functions are also optimized, but only
if the function is constant (always returns the same result for the same parameter values).
If the WHERE clause is always false, then the table is not accessed at all.
<h3>COUNT(*) Optimization</h3>
If the query only counts all rows of a table, then the data is not accessed.
However, this is only possible if no WHERE clause is used, that means it only works for
queries of the form SELECT COUNT(*) FROM table.
<h3>Updating Optimizer Statistics / Column Selectivity</h3>
When executing a query, at most one index per joined table can be used.
If the same table is joined multiple times, for each join only one index is used.
Example: for the query SELECT * FROM TEST T1, TEST T2 WHERE T1.NAME='A' AND T2.ID=T1.ID,
two index can be used, in this case the index on NAME for T1 and the index on ID for T2.
<p>
If a table has multiple indexes, sometimes more than one index could be used.
Example: if there is a table TEST(ID, NAME, FIRSTNAME) and an index on each column,
then two indexes could be used for the query SELECT * FROM TEST WHERE NAME='A' AND FIRSTNAME='B',
the index on NAME or the index on FIRSTNAME. It is not possible to use both indexes at the same time.
Which index is used depends on the selectivity of the column. The selectivity describes the 'uniqueness' of
values in a column. A selectivity of 100 means each value appears only once, and a selectivity of 1 means
the same value appears in many or most rows. For the query above, the index on NAME should be used
if the table contains more distinct names than first names.
<p>
The SQL statement ANALYZE can be used to automatically estimate the selectivity of the columns in the tables.
This command should be run from time to time to improve the query plans generated by the optimizer.
</div></td></tr></table></body></html>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Quickstart
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Quickstart</h1>
<h2>The H2 Console Application</h2>
The Console lets you access a SQL database using a browser interface.
<br>
<img src="console.png" alt="Web Browser - H2 Console Server - H2 Database">
<br>
If you don't have Windows XP, or if something does not work as expected,
please see the detailed description in the <a href="tutorial.html">Tutorial</a>.
<h3>Step-by-Step</h3>
<h4>Installation</h4>
Install the software using the Windows Installer (if you did not yet do that).
<h4>Start the Console</h4>
Click <span class="button">Start</span>,
<span class="button">All Programs</span>,
<span class="button">H2</span>, and
<span class="button">H2 Console (Native)</span>:<br>
<img class="screenshot" src="quickstart-1.png" alt="screenshot: start H2 Console"><br>
A new console window appears:<br>
<img class="screenshot" src="quickstart-2.png" alt="screenshot: H2 Running"><br>
Also, a new browser page should open with URL <a href="http://localhost:8082" target="_blank">http://localhost:8082</a>.
You may get a security warning from the firewall. If you don't want other computers in the network to access the database
on your machine, you can let the firewall block these connections. Only local connections are required at this time.
<h4>Login</h4>
Select <span class="button">Generic H2</span> and click <span class="button">Connect</span>:<br>
<img class="screenshot" src="quickstart-3.png" alt="screenshot: Login screen"><br>
You are now logged in.
<h4>Sample</h4>
Click on the <span class="button">Sample SQL Script</span>:<br>
<img class="screenshot" src="quickstart-4.png" alt="screenshot: click on the sample SQL script"><br>
The SQL commands appear in the command area.<br>
<h4>Execute</h4>
Click <span class="button">Run</span>:<br>
<img class="screenshot" src="quickstart-5.png" alt="screenshot: click Run"><br>
On the left side, a new entry TEST is added below the database icon.
The operations and results of the statements are shown below the script.<br>
<img class="screenshot" src="quickstart-6.png" alt="screenshot: see the result"><br>
<h4>Disconnect</h4>
Click on <span class="button">Disconnect</span>:<br>
<img src="icon_disconnect.gif" alt="Disconnect icon"><br>
to close the database.
<h4>End</h4>
Close the console window.
For more information, see the <a href="tutorial.html">Tutorial</a>.
</div></td></tr></table></body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Search</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="search.js"></script>
<script type="text/javascript" src="navigation.js"></script>
</head>
<body style="margin: 10px 0px 0px 0px;" onload="frameMe('menu');">
<div class="menu">
<img border="0" src="h2-logo.png" alt="H2 Logo" onclick="document.location='main.html'"/>
</div>
<form name="searchForm" action="submit" onsubmit="return goFirst();">
<table width=100% class="search">
<tr class="search">
<td class="search" colspan="2">
<b>Search:</b>
</td>
</tr>
<tr class="search">
<td class="search" colspan="2">
<input id="search" name="search" type="text" size="21" maxlength="100" onKeyup="listWords(this.value, '')"><br>
<input type="reset" id="clear" style="display:none;" value="Clear" onclick="listWords('', '');">
</td>
</tr>
<tr class="search" style="display:none;" >
<td width="1%" class="search" style="vertical-align: middle;"><input id="highlight" type="checkbox" checked="checked" onclick="highlightCurrent(this.checked, search.value)"></td>
<td width="99%" class="search" style="padding: 0px; vertical-align: middle;">Highlight keyword(s)</td>
</tr>
<tr class="search">
<td class="search" colspan="2">
<table id="result" style="border: 0px;">
</table>
</td>
</tr>
</table>
</form>
<div class="menu">
<b><a href="main.html" target="main">Home</a></b><br>
<a href="quickstartText.html" target="main">Quickstart</a><br>
<a href="installation.html" target="main">Installation</a><br>
<a href="tutorial.html" target="main">Tutorial</a><br>
<a href="features.html" target="main">Features</a><br>
<a href="performance.html" target="main">Performance</a><br>
<a href="advanced.html" target="main">Advanced Topics</a><br>
<br>
<b>Reference</b><br>
<a href="grammar.html" target="main">SQL Grammar</a><br>
<a href="functions.html" target="main">Functions</a><br>
<a href="datatypes.html" target="main">Data Types</a><br>
<a href="../javadoc/index.html" target="main">Javadoc JDBC API</a><br>
<a href="../h2.pdf" target="_blank">Documentation as PDF</a><br>
<br>
<b>Appendix</b><br>
<a href="build.html" target="main">Build</a><br>
<a href="history.html" target="main">History and Roadmap</a><br>
<a href="faq.html" target="main">FAQ and Known Bugs</a><br>
<a href="license.html" target="main">License</a><br>
<br>
</div>
</body>
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
*/
var pages=new Array();
var ref=new Array();
var firstLink = null;
var firstLinkWord = null;
String.prototype.endsWith = function(suffix) {
var startPos = this.length - suffix.length;
if (startPos < 0) {
return false;
}
return (this.lastIndexOf(suffix, startPos) == startPos);
};
function listWords(value, open) {
value = replaceOtherChars(value);
value = trim(value);
if(pages.length==0) {
load();
}
var table = document.getElementById('result');
while(table.rows.length > 0) {
table.deleteRow(0);
}
firstLink=null;
var clear = document.getElementById('clear');
if(value.length == 0) {
clear.style.display = 'none';
return true;
}
clear.style.display = '';
var keywords = value.split(' ');
if(keywords.length > 1) {
listAnd(keywords);
return true;
}
if(value.length < 3) {
max = 100;
} else {
max = 1000;
}
value = value.toLowerCase();
var r = ref[value.substring(0,1)];
if(r==undefined) {
return true;
}
var x=0;
var words = r.split(';');
var count=0;
for(var i=0; i<words.length; i++) {
var wordRef = words[i];
if(wordRef.toLowerCase().indexOf(value)==0) {
count++;
}
}
for(var i=0; i<words.length && (x<=max); i++) {
var wordRef = words[i];
if(wordRef.toLowerCase().indexOf(value)==0) {
word = wordRef.split("=")[0];
var tr = table.insertRow(x++);
var td = document.createElement('td');
var tdc = document.createAttribute('class');
tdc.nodeValue = 'searchKeyword';
td.setAttributeNode(tdc);
var ah = document.createElement('a');
var hre = document.createAttribute('href');
hre.nodeValue = 'javascript:set("' + word + '");';
var link = document.createTextNode(word);
ah.setAttributeNode(hre);
ah.appendChild(link);
td.appendChild(ah);
tr.appendChild(td);
pis = wordRef.split("=")[1].split(",");
if(count<20 || open==word) {
x = addReferences(x, pis, word);
}
}
}
if(x==0) {
noResults(table);
}
return true;
}
function set(v) {
if(pages.length==0) {
load();
}
var search = document.getElementById('search').value;
listWords(search, v);
document.getElementById('search').focus();
window.scrollBy(-20, 0);
}
function goFirst() {
var table = document.getElementById('result');
if(firstLink != null) {
go(firstLink, firstLinkWord);
}
return false;
}
function go(pageId, word) {
var page = pages[pageId];
var load = '../' + page.file + '?highlight=' + encodeURIComponent(word);
if(!top.main.location.href.endsWith(page.file)) {
top.main.location = load;
}
}
function listAnd(keywords) {
var count = new Array();
var weight = new Array();
for(var i=0; i<pages.length; i++) {
count[i] = 0;
weight[i] = 0;
}
for(var i=0; i<keywords.length; i++) {
var value = keywords[i].toLowerCase();
var r = ref[value.substring(0,1)];
if(r==undefined) {
return true;
}
var words = r.split(';');
for(var j=0; j<words.length; j++) {
var wordRef = words[j];
if(wordRef.toLowerCase().indexOf(value)==0) {
pis = wordRef.split("=")[1].split(",");
var w=1;
for(var k=0; k<pis.length; k++) {
var pi = pis[k];
if(pi.charAt(0) == 't') {
pi = pi.substring(1);
w=10000;
} else if(pi.charAt(0) == 'h') {
pi = pi.substring(1);
w=100;
} else if(pi.charAt(0) == 'r') {
pi = pi.substring(1);
w=1;
}
if(count[pi]>=i) {
if(count[pi]==i) {
count[pi]++;
}
weight[pi]+=w;
}
}
}
}
}
var x = 0;
var table = document.getElementById('result');
var pis = new Array();
var piw = new Array();
for(var i=0; i<pages.length; i++) {
if(count[i] >= keywords.length) {
pis[x] = '' + i;
piw[x] = weight[i];
x++;
}
}
// sort
for (var i = 1, j; i < x; i++) {
var tw = piw[i];
var ti = pis[i];
for (j = i - 1; j >= 0 && (piw[j] < tw); j--) {
piw[j + 1] = piw[j];
pis[j + 1] = pis[j];
}
piw[j + 1] = tw;
pis[j + 1] = ti;
}
addReferences(0, pis, keywords);
if(pis.length == 0) {
noResults(table);
}
}
function addReferences(x, pis, word) {
var table = document.getElementById('result');
for(var j=0; j<pis.length; j++) {
var pi = pis[j];
if(pi.charAt(0) == 't') {
pi = pi.substring(1);
} else if(pi.charAt(0) == 'h') {
pi = pi.substring(1);
} else if(pi.charAt(0) == 'r') {
pi = pi.substring(1);
}
var tr = table.insertRow(x++);
var td = document.createElement('td');
var tdc = document.createAttribute('class');
tdc.nodeValue = 'searchLink';
td.setAttributeNode(tdc);
var ah = document.createElement('a');
var hre = document.createAttribute('href');
var thisLink = 'javascript:go(' + pi + ', "' + word + '")';
if(firstLink==null) {
firstLink = pi;
firstLinkWord = word;
}
hre.nodeValue = thisLink;
ah.setAttributeNode(hre);
var page = pages[pi];
var link = document.createTextNode(page.title);
ah.appendChild(link);
td.appendChild(ah);
tr.appendChild(td);
}
return x;
}
function trim(s) {
while(s.charAt(0)==' ' && s.length>0) {
s=s.substring(1);
}
while(s.charAt(s.length-1)==' ' && s.length>0) {
s=s.substring(0, s.length-1);
}
return s;
}
function replaceOtherChars(s) {
var x = "";
for(var i=0; i<s.length; i++) {
var c = s.charAt(i);
if("\t\r\n\"'.,:;!&/\\?%@`[]{}()+-=<>|*^~#$".indexOf(c) >= 0) {
c = " ";
}
x += c;
}
return x;
}
function noResults(table) {
var tr = table.insertRow(0);
var td = document.createElement('td');
var tdc = document.createAttribute('class');
tdc.nodeValue = 'searchKeyword';
td.setAttributeNode(tdc);
var text = document.createTextNode('No results found');
td.appendChild(text);
tr.appendChild(td);
}
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
td, input, select, textarea, body, code, pre, td, th {
font: 8pt/130% Tahoma, Arial, Helvetica, sans-serif;
font-weight: normal;
}
h1, h2, h3, h4, h5 {
font: 8pt Arial, Helvetica, sans-serif;
font-weight: bold;
}
td, input, select, textarea, body, code, pre {
font-size: 8pt;
}
pre {
background-color: #ece9d8;
border: 1px solid rgb(172, 168, 153);
padding: 4px;
}
body {
margin: 0px;
}
h1 {
background-color: #0000bb;
padding: 2px 4px 2px 4px;
color: #fff;
font-size: 15pt;
line-height: normal;
}
h2 {
font-size: 13pt;
}
h3 {
font-size: 10pt;
margin-bottom: 5px;
}
h4 {
font-size: 9pt;
}
hr {
color: #CCC;
background-color: #CCC;
height: 1px;
border: 0px solid blue;
}
table {
background-color: #ffffff;
border-collapse: collapse;
border: 1px solid #aca899;
}
th {
text-align: left;
background-color: #ece9d8;
border: 1px solid #aca899;
padding: 2px;
}
td {
background-color: #ffffff;
text-align: left;
vertical-align: top;
border: 1px solid #aca899;
padding: 2px;
}
form {
}
ul, ol {
list-style-position: outside;
padding-left: 20px;
}
li {
margin-top: 2px;
}
a {
text-decoration: none;
color: #0000ff;
}
a:hover {
text-decoration: underline;
}
.button {
border: 1px outset #800;
margin: 0px 2px 0px 2px;
padding: 0px 4px 0px 4px;
font-weight: bold;
}
.menu {
margin: 10px 10px 10px 10px;
}
table.search {
width: 100%;
border: 0px;
}
tr.search {
border: 0px;
}
td.search {
border: 0px;
padding: 2px 0px 2px 10px;
}
td.searchKeyword {
border: 0px;
padding: 0px 0px 0px 2px;
}
td.searchKeyword a {
text-decoration: none;
color: #000000;
}
td.searchKeyword a:hover {
text-decoration: underline;
}
td.searchLink {
border: 0px;
padding: 0px 0px 0px 42px;
text-indent: -16px;
}
td.searchLink a {
text-decoration: none;
color: #0000ff;
}
td.searchLink a:hover {
text-decoration: underline;
}
table.content {
width: 100%;
height: 100%;
border: 0px;
}
tr.content {
border:0px;
border-left:1px solid #aca899;
}
td.content {
border:0px;
border-left:1px solid #aca899;
}
.contentDiv {
margin:10px;
}
.screenshot {
border: 1px outset #800;
padding: 10px;
margin: 10px 0px;
}
.compareFeature {
}
.compareY {
color: #050;
}
.compareN {
color: #800;
}
\ No newline at end of file
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
td, input, select, textarea, body, code, pre, td, th {
font: 8pt Tahoma, Arial, Helvetica, sans-serif;
font-weight: normal;
}
h1, h2, h3, h4, h5 {
font: 8pt Arial, Helvetica, sans-serif;
font-weight: bold;
}
td, input, select, textarea, body, code, pre {
font-size: 8pt;
}
pre {
background-color: #ece9d8;
border: 1px solid rgb(172, 168, 153);
padding: 4px;
}
body {
margin: 0px;
}
h1 {
background-color: #0000bb;
padding: 2px 4px 2px 4px;
color: #fff;
font-size: 15pt;
line-height: normal;
}
h2 {
font-size: 13pt;
}
h3 {
font-size: 10pt;
margin-bottom: 5px;
}
h4 {
font-size: 9pt;
}
hr {
color: #CCC;
background-color: #CCC;
height: 1px;
border: 0px solid blue;
}
table {
background-color: #ffffff;
border-collapse: collapse;
border: 1px solid #aca899;
}
th {
font-size: 8pt;
font-weight: normal;
text-align: left;
background-color: #ece9d8;
border: 1px solid #aca899;
padding: 2px;
}
td {
background-color: #ffffff;
font-size: 8pt;
text-align: left;
vertical-align: top;
border: 1px solid #aca899;
padding: 2px;
margin: 0px;
}
form {
}
ul, ol {
list-style-position: outside;
padding-left: 20px;
}
li {
margin-top: 2px;
}
a {
text-decoration: none;
color: #0000ff;
}
a:hover {
text-decoration: underline;
}
.screenshot {
border: 1px outset #888;
padding: 10px;
margin: 10px 0px;
}
.compareFeature {
}
.compareY {
color: #050;
}
.compareN {
color: #800;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><title>
Tutorial
</title><link rel="stylesheet" type="text/css" href="stylesheet.css">
<script type="text/javascript" src="navigation.js"></script>
</head><body onload="frameMe();">
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<h1>Tutorial</h1>
<a href="#tutorial_starting_h2_console">
Starting and Using the H2 Console</a><br />
<a href="#connecting_using_jdbc">
Connecting to a Database using JDBC</a><br />
<a href="#creating_new_databases">
Creating New Databases</a><br />
<a href="#using_server">
Using the Server</a><br />
<a href="#using_hibernate">
Using Hibernate</a><br />
<a href="#web_applications">
Using Databases in Web Applications</a><br />
<a href="#csv">
CSV (Comma Separated Values) Support</a><br />
<a href="#upgrade_backup_restore">
Upgrade, Backup, and Restore</a><br />
<br /><a name="tutorial_starting_h2_console"></a>
<h2>Starting and Using the H2 Console</h2>
This application lets you access a SQL database using a browser interface.
This can be a H2 database, or another database that supports the JDBC API.
<br>
<img src="console.png" alt="Web Browser - H2 Console Server - H2 Database">
<br>
This is a client / server application, so both a server and a client are required to run it.
<p>
Depending on your platform and environment, there are multiple ways to start the application:
<table><tr><th>OS</th><th>Java</th><th>Start</th>
<tr>
<td>Windows</td>
<td>1.4 or 1.5</td>
<td>
Click [Start], [All Programs], [H2], and [H2 Console]<br>
If this worked correctly, an icon will be added to the system tray:
<img src="h2.png" alt="[H2 icon]"/><br>
If you don't get the system tray icon, then maybe Java is not installed correctly (in this case, try another way to start the application).
A browser window should open
and point to the Login page (URL: <a href="http://localhost:8082" target="_blank">http://localhost:8082</a>).
</td>
</tr>
<tr>
<td>Windows</td>
<td>1.4 or 1.5</td>
<td>
Open a file browser, navigate to h2/bin, and double click on h2.bat.<br>
If this worked correctly, an icon will be added to the system tray.
If there is a problem, you will see the error message on the console window.
A browser window will open
and point to the Login page (URL: <a href="http://localhost:8082" target="_blank">http://localhost:8082</a>).
</td>
</tr>
<tr>
<td>Any</td>
<td>1.4 or 1.5</td>
<td>
Open a console window, navigate to the directory 'h2/lib' and type:
<pre>
java -cp h2.jar org.h2.tools.Server
</pre>
</td>
</tr>
</table>
<h3>Firewall</h3>
If you start the server, you may get a security warning from the firewall (if you have installed one).
If you don't want other computers in the network to access the database on your machine, you can
let the firewall block those connections. The connection from the local machine will still work.
Only if you want other computers to access the database on this computer, you need allow remote connections
in the firewall.
<p>
Please not that a small firewall is already built into the server. This mechanism by default does not
allow other computer to connect to the server. This can be changed in the Preferences
(Allow connections from other computers).
<h3>Native Version</h3>
The native version does not require Java, because it is compiled using GCJ.
However H2 does currently not run stable with GCJ on Windows
It is possible to compile the software to different platforms.
<h3>Testing Java</h3>
To check the Java version you have installed, open a command prompt and type:
<pre>
java -version
</pre>
If you get an error message, you may need to add the Java binary directory to the path environment variable.
<h3>Error Message 'Port is in use'</h3>
You can only start one instance of the H2 Console,
otherwise you will get the following error message:
<code>Port is in use, maybe another ... server already running on...</code>.
It is possible to start multiple console applications on the same computer (using different ports),
but this is usually not required as the console supports multiple concurrent connections.
<h3>Using another Port</h3>
If the port is in use by another application, you may want to start the H2 Console on a different port.
This can be done by changing the port in the file .h2.server.properties. This file is stored
in the user directory (for Windows, this is usually in "Documents and Settings/&lt;username&gt;").
The relevant entry is webPort.
<h3>Starting Successfully</h3>
If starting the server from a console window was successful,
a new window will open and display the following text:
<pre>
H2 Server running on port 9092
Webserver running on https://localhost:8082/
</pre>
Don't click inside this window; otherwise you might block the application (if you have the Fast-Edit mode enabled).
<h3>Connecting to the Server using a Browser</h3>
If the server started successfully, you can connect to it using a web browser.
The browser needs to support JavaScript, frames and cascading stylesheets (css).
If you started the server on the same computer as the browser, go to http://localhost:8082 in the browser.
If you want to connect to the application from another computer, you need to provide the IP address of the server, for example:
http://192.168.0.2:8082. If you enabled SSL on the server side, the URL needs to start with HTTPS.
<h3>Multiple Concurrent Sessions</h3>
Multiple concurrent browser sessions are supported. As that the database objects reside on the server,
the amount of concurrent work is limited by the memory available to the server application.
<h3>Application Properties</h3>
Starting the server will create a configuration file in you local home directory called <code>.h2.server.properties</code>.
For Windows installations, this file will be in the directory <code>C:\Documents and Settings\[username]</code>.
This file contains the settings of the application.
<h3>Login</h3>
At the login page, you need to provide connection information to connect to a database.
Set the JDBC driver class of your database, the JDBC URL, user name and password.
If you are done, click [Connect].
<p>
You can save and reuse previously saved settings. The settings are stored in the
Application Properties file.
<h3>Error Messages</h3>
Error messages in are shown in red. You can show/hide the stack trace of the exception
by clicking on the message.
<h3>Adding Database Drivers</h3>
Additional database drivers can be registered by adding the Jar file location of the driver to the environment
variables H2DRIVERS or CLASSPATH. Example (Windows): To add the database driver library
C:\Programs\hsqldb\lib\hsqldb.jar, set the environment variable H2DRIVERS to
C:\Programs\hsqldb\lib\hsqldb.jar.<p>
Multiple drivers can be set; each entry needs to be separated with a ';' (Windows) or ':' (other operating systems).
Spaces in the path names are supported. The settings must not be quoted.
<p>
Only the Java version supports additional drivers (this feature is not supported by the Native version).
<h3>Using the Application</h3>
The application has three main panels, the toolbar on top, the tree on the left and the query / result panel on the right.
The database objects (for example, tables) are listed on the left panel.
Type in a SQL command on the query panel and click 'Run'. The result of the command appears just below the command.
<h3>Inserting Table Names or Column Names</h3>
The table name and column names can be inserted in the script by clicking them in the tree.
If you click on a table while the query is empty, a 'SELECT * FROM ...' is added as well.
While typing a query, the table that was used is automatically expanded in the tree.
For, example if you type 'SELECT * FROM TEST T WHERE T.' then the table TEST is automatically expanded in the tree.
<h3>Disconnecting and Stopping the Application</h3>
On the browser, click 'Disconnect' on the toolbar panel. You will be logged out of the database.
However, the server is still running and ready to accept new sessions.<p>
To stop the server, right click on the system tray icon and select [Exit].
If you don't have the icon (because you started it in another way),
press [Ctrl]+[C] on the console where the server was started (Windows),
or close the console window.
<br /><a name="connecting_using_jdbc"></a>
<h2>Connecting to a Database using JDBC</h2>
To connect to a database, a Java application first needs to load the database driver,
and then get a connection. A simple way to do that is using the following code:
<pre>
import java.sql.*;
public class Test {
public static void main(String[] a)
throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.
getConnection("jdbc:h2:test", "sa", "");
// add application code here
}
}
</pre>
This code first loads the driver (<code>Class.forName()</code>)
and then opens a connection (using <code>DriverManager.getConnection()</code>).
The driver name is <code>"org.h2.Driver"</code> in every case.
The database URL always needs to start with <code>jdbc:h2:</code>
to be recognized by this database. The second parameter in the <code>getConnection()</code> call
is the user name ('sa' for System Administrator in this example). The third parameter is the password.
Please note that in this database, user names are not case sensitive, but passwords are case sensitive.
<br /><a name="creating_new_databases"></a>
<h2>Creating New Databases</h2>
By default, if the database specified in the URL does not yet exist, a new (empty)
database is created automatically.
<br /><a name="using_server"></a>
<h2>Using the Server</h2>
H2 currently supports three servers: a Web Server, a TCP Server and an ODBC Server.
The servers can be started in different ways.
<h3>Limitations of the Server</h3>
There currently are a few limitations when using the server or cluster mode:
<ul>
<li>Statement.cancel() is only supported in embedded mode.
A connection can only execute one operation at a time in server or cluster mode,
and is blocked until this operation is finished.
<li>CLOBs and BLOBs are sent to the server in one piece and not as a stream.
That means those objects need to fit in memory when using the server or cluster mode.
</ul>
<h3>Starting from Command Line</h3>
To start the Server from the command line with the default settings, run
<pre>
java org.h2.tools.Server
</pre>
This will start the Server with the default options. To get the list of options, run
<pre>
java org.h2.tools.Server -?
</pre>
The native version can also be started in this way:
<pre>
h2-server -?
</pre>
There are options available to use a different ports, and start or not start
parts of the Server and so on. For details, see the API documentation of the Server tool.
<h3>Starting within an Application</h3>
It is also possible to start and stop a Server from within an application. Sample code:
<pre>
import org.h2.tools.Server;
...
// start the TCP Server with SSL enabled
String[] args = new String[]{"-ssl", "true"};
Server server = Server.startTcpServer(args);
...
// stop the TCP Server
server.stop();
</pre>
<h3>Stopping a TCP Server from Another Process</h3>
The TCP Server can be stopped from another process.
To stop the server from the command line, run:
<pre>
java org.h2.tools.Server -tcpShutdown tcp://localhost:9092
</pre>
To stop the server from a user application, use the following code:
<pre>
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094");
</pre>
This function will call System.exit on the server.
This function should be called after all connection to the databases are closed
to avoid recovery when the databases are opened the next time.
To stop remote server, remote connections must be enabled on the server.
<br /><a name="using_hibernate"></a>
<h2>Using Hibernate</h2>
This database supports Hibernate version 3.1 and newer. You can use the HSQLDB Dialect,
or the native H2 Dialect that is available in the file src/tools/org/h2/tools/hibernate/H2Dialect.txt.
This dialect will be integrated into Hibernate, but until this is done you need to copy the file
into the folder src\org\hibernate\dialect (Hibernate 3.1), rename it to H2Dialect.java and re-compile hibernate.
<br /><a name="web_applications"></a>
<h2>Using Databases in Web Applications</h2>
There are multiple ways to access a database from within web
applications. Here are some examples if you use Tomcat or JBoss.
<h3>Embedded Mode</h3>
The (currently) most simple solution is to use the database in the
embedded mode, that means open a connection in your application when
it starts (a good solution is using a Servlet Listener, see below), or
when a session starts. A database can be accessed from multiple
sessions and applications at the same time, as long as they run in the
same process. Most Servlet Containers (for example Tomcat) are just
using one process, so this is not a problem (unless you run Tomcat in
clustered mode). Tomcat uses multiple threads and multiple
classloaders. If multiple applications access the same database at the
same time, you need to put the database jar in the shared/lib or
server/lib directory. It is a good idea to open the database when the
web application starts, and close it when the web applications stops.
If using multiple applications, only one (any) of them needs to do
that. In the application, an idea is to use one connection per
Session, or even one connection per request (action). Those
connections should be closed after use if possible (but it's not that
bad if they don't get closed).
<h3>Server Mode</h3>
The server mode is similar, but it allows you to run the server in another process.
<h3>Using a Servlet Listener to Start and Stop a Database</h3>
Add the following to the web.xml file (after context-param and before filter):
<pre>
&lt;listener>
&lt;listener-class>db.Starter&lt;/listener-class>
&lt;/listener>
</pre>
Add the following Starter class:
<pre>
package org.h2.tools.servlet;
import javax.servlet.*;
import java.sql.*;
public class DbStarter implements ServletContextListener {
private Connection conn;
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Class.forName("org.h2.Driver");
// You can also get the setting from a context-param in web.xml:
// ServletContext servletContext = servletContextEvent.getServletContext();
// String url = servletContext.getInitParameter("db.url");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
} catch (Exception e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return conn;
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
<br /><a name="csv"></a>
<h2>CSV (Comma Separated Values) Support</h2>
The CSV file support can be used inside the database using the functions CSVREAD and CSVWRITE,
and the CSV library can be used outside the database as a standalone tool.
<h3>Writing a CSV File from Within a Database</h3>
The built-in function CSVWRITE can be used to create a CSV file from a query.
Example:
<pre>
CREATE TABLE TEST(ID INT, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');
CALL CSVWRITE('test.csv', 'SELECT * FROM TEST');
</pre>
<h3>Reading a CSV File from Within a Database</h3>
A CSV file can be read using the function CSVREAD. Example:
<pre>
SELECT * FROM CSVREAD('test.csv');
</pre>
<h3>Writing a CSV File from a Java Application</h3>
The CSV tool can be used in a Java application even when not using a database at all.
Example:
<pre>
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
rs.addColumn("PHONE", Types.VARCHAR, 255, 0);
rs.addRow(new String[]{"Bob Meier", "bob.meier@abcde.fgh", "+41123456789"});
rs.addRow(new String[]{"John Jones", "johnjones@abcde.fgh", "+41976543210"});
Csv.write("test.csv", rs, null);
</pre>
<h3>Reading a CSV File from a Java Application</h3>
It is possible to read a CSV file without opening a database.
Example:
<pre>
ResultSet rs = Csv.read("test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData();
while(rs.next()) {
for(int i=0; i&lt;meta.getColumnCount(); i++) {
System.out.println(meta.getColumnLabel(i+1) + ": " + rs.getString(i+1));
}
System.out.println();
}
rs.close();
</pre>
<br /><a name="upgrade_backup_restore"></a>
<h2>Upgrade, Backup, and Restore</h2>
<h3>Database Upgrade</h3>
The recommended way to upgrade from one version of the database engine to the next
version is to create a backup of the database (in the form of a SQL script) using the old engine,
and then execute the SQL script using the new engine.
<h3>Backup</h3>
There are different ways to backup a database. For example, it is possible to copy the database files.
However, this is not recommended while the database is in use. Also, the database files are not human readable
and quite large. The recommended way to backup a database is to create a compressed SQL script file.
This can be done using the backup tool:
<pre>
java org.h2.tools.Backup -url jdbc:h2:test -user sa -script test.zip -options compression zip
</pre>
For more information about the options, see the SQL command SCRIPT.
The backup can be done remotely, however the file will be created on the server side.
The built in FTP server could be used to retrieve the file from the server.
It is also possible to use the SQL command SCRIPT to create the backup of the database.
<h3>Restore</h3>
To restore a database from a SQL script file, you can use the RunScript tool:
<pre>
java org.h2.tools.RunScript -url jdbc:h2:test -user sa -script test.zip -options compression zip
</pre>
For more information about the options, see the SQL command RUNSCRIPT.
The restore can be done remotely, however the file needs to be on the server side.
The built in FTP server could be used to copy the file to the server.
It is also possible to use the SQL command RUNSCRIPT to execute a SQL script.
SQL script files may contain references to other script files, in the form of
RUNSCRIPT commands. However, when using the server mode, the references script files
need to be available on the server side.
</div></td></tr></table></body></html>
\ No newline at end of file
<!--
Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>H2 Database Engine</title>
<link rel="stylesheet" type="text/css" href="html/stylesheet.css">
<script type="text/javascript">
location.href = 'html/frame.html';
</script>
</head>
<body style="margin: 20px;">
<h1>H2 Database Engine</h1>
<p>
Welcome to H2, the free SQL database. The main feature of H2 are:
<ul>
<li>It is free to use for everybody, source code is included
<li>Written in Java, but also available as native executable
<li>JDBC and (partial) ODBC API
<li>Embedded and client/server modes
<li>Clustering is supported
<li>A web client is included
</ul>
</p>
<h2>No Javascript</h2>
If you are not automatically redirected to the main page, then
Javascript is currently disabled or your browser does not support Javascript.
Some features (for example the integrated search) require Javascript.
<p>
Please enable Javascript, or go ahead without it:
<p>
<a href="html/frame.html" style="font-size: 16px; font-weight: bold">H2 Database Engine</a>
</body>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论