提交 d059ca51 authored 作者: Thomas Mueller's avatar Thomas Mueller

Documentation: improved website translation

上级 20294dfb
......@@ -102,9 +102,9 @@ when reading the data, the blocks are merged together.
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.
To store a BLOB, use <code>PreparedStatement.setBinaryStream</code>. To store a CLOB, use
<code>PreparedStatement.setCharacterStream</code>. To read a BLOB, use <code>ResultSet.getBinaryStream</code>,
and to read a CLOB, use <code>ResultSet.getCharacterStream</code>.
When using the client/server mode, large BLOB and CLOB data is stored in a temporary file
on the client side.
</p>
......@@ -156,8 +156,8 @@ If multiple linked tables point to the same database (using the same database UR
is shared. To disable this, set the system property <code>h2.shareLinkedConnections=false</code>.
</p>
<p>
The <code>CREATE LINKED TABLE</code> statement supports an optional schema name parameter.
See the grammar for details.
The statement <a href="grammar.html#create_linked_table" class="notranslate" >CREATE LINKED TABLE</a>
supports an optional schema name parameter.
</p>
<br />
......@@ -165,7 +165,7 @@ See the grammar for details.
<p>
Transaction isolation is provided for all data manipulation language (DML) statements.
Most data definition language (DDL) statements commit the current transaction.
See the <a href="grammar.html">grammar</a> for details.
See the <a href="grammar.html">Grammar</a> for details.
</p>
<p>
This database supports the following transaction isolation levels:
......@@ -465,7 +465,7 @@ See also:
<h3>ODBC Installation</h3>
<p>
First, the ODBC driver must be installed.
Any recent PostgreSQL ODBC driver should work, however version 8.2 (psqlodbc-08_02*) or newer is recommended.
Any recent PostgreSQL ODBC driver should work, however version 8.2 (<code>psqlodbc-08_02*</code>) or newer is recommended.
The Windows version of the PostgreSQL ODBC driver is available at
<a href="http://www.postgresql.org/ftp/odbc/versions/msi">http://www.postgresql.org/ftp/odbc/versions/msi</a>.
</p>
......@@ -480,7 +480,7 @@ java -cp h2*.jar org.h2.tools.Server
<p>
The PG Server (PG for PostgreSQL protocol) is started as well.
By default, databases are stored in the current working directory where the server is started.
Use -baseDir to save databases in another directory, for example the user home directory:
Use <code>-baseDir</code> to save databases in another directory, for example the user home directory:
</p>
<pre>
java -cp h2*.jar org.h2.tools.Server -baseDir ~
......@@ -569,18 +569,18 @@ An implementation of the ADO.NET interface is available in the open source proje
<ul><li>Install the .NET Framework from <a href="http://www.microsoft.com">Microsoft</a>.
Mono has not yet been tested.
</li><li>Install <a href="http://www.ikvm.net">IKVM.NET</a>.
</li><li>Copy the h2*.jar file to ikvm/bin
</li><li>Copy the <code>h2*.jar</code> file to <code>ikvm/bin</code>
</li><li>Run the H2 Console using:
<code>ikvm -jar h2*.jar</code>
</li><li>Convert the H2 Console to an .exe file using:
</li><li>Convert the H2 Console to an <code>.exe</code> file using:
<code>ikvmc -target:winexe h2*.jar</code>.
You may ignore the warnings.
</li><li>Create a .dll file using (change the version accordingly):
</li><li>Create a <code>.dll</code> file using (change the version accordingly):
<code>ikvmc.exe -target:library -version:1.0.69.0 h2*.jar</code>
</li></ul>
<p>
If you want your C# application use H2, you need to add the h2.dll and the
IKVM.OpenJDK.ClassLibrary.dll to your C# solution. Here some sample code:
If you want your C# application use H2, you need to add the <code>h2.dll</code> and the
<code>IKVM.OpenJDK.ClassLibrary.dll</code> to your C# solution. Here some sample code:
</p>
<pre>
using System;
......@@ -658,7 +658,7 @@ Making sure that committed transactions are not lost is more complicated than it
To guarantee complete durability, a database must ensure that the log record is on the hard drive
before the commit call returns. To do that, databases use different methods. One
is to use the 'synchronous write' file access mode. In Java, <code>RandomAccessFile</code>
supports the modes <code>"rws"</code> and <code>"rwd"</code>:
supports the modes <code>rws</code> and <code>rwd</code>:
</p>
<ul>
<li><code>rwd</code>: every update to the file's content is written synchronously to the underlying storage device.
......@@ -675,25 +675,25 @@ then the disk would need to make at least 50 thousand revolutions per second, or
or about 120 revolutions per second. There is an overhead, so the maximum write rate must be lower than that.
</p>
<p>
Calling fsync flushes the buffers. There are two ways to do that in Java:
Calling <code>fsync</code> flushes the buffers. There are two ways to do that in Java:
</p>
<ul>
<li><code>FileDescriptor.sync()</code>. The documentation says that this forces 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 FileDescriptor
This method is supposed to return after all in-memory modified copies of buffers associated with this file descriptor
have been written to the physical medium.
</li><li><code>FileChannel.force()</code> (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.
</li></ul>
<p>
By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations
By default, MySQL calls <code>fsync</code> for each commit. When using one of those methods, only around 60 write operations
per second can be achieved, which is consistent with the RPM rate of the hard drive used.
Unfortunately, even when calling <code>FileDescriptor.sync()</code> or
<code>FileChannel.force()</code>,
data is not always persisted to the hard drive, because most hard drives do not obey
fsync(): see
<code>fsync()</code>: see
<a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a>.
In Mac OS X, fsync does not flush hard drive buffers. See
In Mac OS X, <code>fsync</code> does not flush hard drive buffers. See
<a href="http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html">Bad fsync?</a>.
So the situation is confusing, and tests prove there is a problem.
</p>
......@@ -777,7 +777,7 @@ The default method for database file locking is the 'File Method'. The algorithm
<ul>
<li>If the lock file does not exist, it is created (using the atomic operation
<code>File.createNewFile</code>).
Then, the process waits a little bit (20ms) and checks the file again. If the file was changed
Then, the process waits a little bit (20 ms) and checks the file again. If the file was changed
during this time, the operation is aborted. This protects against a race condition
when one process deletes the lock file just after another one create it, and a third process creates
the file again. It does not occur if there are only two writers.
......@@ -859,7 +859,7 @@ SELECT * FROM USERS WHERE PASSWORD='' OR ''='';
</pre>
<p>
Which is always true no matter what the password stored in the database is.
For more information about SQL Injection, see Glossary and Links.
For more information about SQL Injection, see <a href="#glossary_links">Glossary and Links</a>.
</p>
<h3>Disabling Literals</h3>
......@@ -951,7 +951,7 @@ CALL GET_PROPERTY('abc');
To restrict users (including admins) from loading classes and executing code,
the list of allowed classes can be set in the system property
<code>h2.allowedClasses</code>
in the form of a comma separated list of classes or patterns (items ending with '*').
in the form of a comma separated list of classes or patterns (items ending with <code>*</code>).
By default all classes are allowed. Example:
</p>
<pre>
......@@ -1011,8 +1011,8 @@ 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><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
When a user tries to connect to an encrypted database, the combination of
<code>file@</code> and the file password is hashed using SHA-256. This hash value is
transmitted to the server.
</p><p>
When a new database file is created, a new cryptographically secure
......
......@@ -78,7 +78,7 @@ build -?
For Linux and OS X, use <code>./build.sh</code> instead of <code>build</code>.
</p>
<p>
You will get a list of targets. If you want to build the jar file, execute (Windows):
You will get a list of targets. If you want to build the <code>jar</code> file, execute (Windows):
</p>
<pre>
build jar
......@@ -87,7 +87,7 @@ build jar
<h3>Switching the Source Code</h3>
<p>
By default the source code uses Java 1.5 features, however Java 1.6 is supported as well.
To switch the source code to the install version of Java, run:
To switch the source code to the installed version of Java, run:
</p>
<pre>
build switchSource
......@@ -131,13 +131,13 @@ Example:
</pre>
<p>
New versions of this database are first uploaded to http://hsql.sourceforge.net/m2-repo/ and then automatically
synchronized with the main maven repository; however after a new release it may take a few hours before
synchronized with the main Maven repository; however after a new release it may take a few hours before
they are available there.
</p>
<h3>Using Snapshot Version</h3>
<p>
To build a 'snapshot' H2 jar file and upload it the to the local Maven 2 repository, execute the following command:
To build a <code>h2-*-SNAPSHOT.jar</code> file and upload it the to the local Maven 2 repository, execute the following command:
</p>
<pre>
build mavenInstallLocal
......@@ -177,7 +177,7 @@ using <code>build docs</code>.
<p>
If you like to provide patches, please consider the following guidelines to simplify merging them:
</p>
<ul><li>Only use Java 1.5 features (do not use Java 1.6) (see Environment).
<ul><li>Only use Java 1.5 features (do not use Java 1.6) (see <a href="#environment">Environment</a>).
</li><li>Follow the coding style used in the project, and use Checkstyle (see above) to verify.
For example, do not use tabs (use spaces instead).
The checkstyle configuration is in <code>src/installer/checkstyle.xml</code>.
......@@ -191,11 +191,11 @@ If you like to provide patches, please consider the following guidelines to simp
</li><li>Verify that you did not break other features: run the test cases by executing
<code>build test</code>.
</li><li>Provide end user documentation if required (<code>src/docsrc/html/*</code>).
</li><li>Document grammar changes in <code>src/main/org/h2/res/help.csv</code>
</li><li>Document grammar changes in <code>src/docsrc/help/help.csv</code>
</li><li>Provide a change log entry (<code>src/docsrc/html/changelog.html</code>).
</li><li>Verify the spelling using <code>build spellcheck</code>. If required
add the new words to <code>src/tools/org/h2/build/doc/dictionary.txt</code>.
</li><li>Run the <code>src/installer/buildRelease</code> to find and fix formatting errors.
</li><li>Run <code>src/installer/buildRelease</code> to find and fix formatting errors.
</li><li>Verify the formatting using <code>build docs</code> and
<code>build javadoc</code>.
</li><li>Submit patches as <code>.patch</code> files (compressed if big).
......
......@@ -50,9 +50,9 @@ Here is the list of known and confirmed issues:
unloading a web application. This can cause a <code>NullPointerException</code> in H2 versions
1.1.107 and older, and may still not work in newer versions. Please report it if you
run into this issue. In Tomcat >= 6.0 this behavior can be disabled by setting the
system property <code>org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES</code>
to false, however Tomcat may then run out of memory. A known workaround is to
put the h2.jar file in a shared <code>lib</code> directory
system property <code>org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false</code>,
however Tomcat may then run out of memory. A known workaround is to
put the <code>h2*.jar</code> file in a shared <code>lib</code> directory
(<code>common/lib</code>).
</li><li>Some problems have been found with right outer join. Internally, it is converted
to left outer join, which does not always produce the same results as other databases
......@@ -110,11 +110,11 @@ Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
<p>
When using database URLs like <code>jdbc:h2:~/test</code>,
the database is stored in the user directory.
For Windows, this is usually C:\Documents and Settings\&lt;userName&gt;.
For Windows, this is usually <code>C:\Documents and Settings\&lt;userName&gt;</code>.
If the base directory is not set (as in <code>jdbc:h2:test</code>),
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 "&lt;Installation Directory&gt;/bin".
this is <code>&lt;Installation Directory&gt;/bin</code>.
The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL
<code>jdbc:h2:file:data/sample</code>, the database is stored in the directory
<code>data</code> (relative to the current working directory).
......@@ -132,14 +132,6 @@ See <a href="advanced.html#limits_limitations">Limits and Limitations</a>.
<br />
<h3 id="reliable">Is it Reliable?</h3>
<p>
Some users have reported that after a power failure, the database can sometimes not be
opened because the index file is corrupt. In that case, the index file can be deleted
(it is automatically re-created). To avoid this, append
<code>;LOG=2</code> to the database URL.
See also: <a href="grammar.html#set_log" class="notranslate">SET LOG</a>. This problem will be solved
using the new 'page store' mechanism (currently beta).
</p>
<p>
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 there are probably still
......@@ -175,7 +167,6 @@ Areas that are not fully tested:
</li><li>Fulltext search
</li><li>Operations on LOBs over 2 GB
</li></ul>
<p>
Areas considered experimental are:
</p>
......@@ -184,6 +175,14 @@ Areas considered experimental are:
</li><li>Multi-threading within the engine using <code>SET MULTI_THREADED=1</code>
</li><li>Compatibility modes for other databases (only some features are implemented)
</li></ul>
<p>
Some users have reported that after a power failure, the database can sometimes not be
opened because the index file is corrupt. In that case, the index file can be deleted
(it is automatically re-created). To avoid this, append
<code>;LOG=2</code> to the database URL.
See also: <a href="grammar.html#set_log" class="notranslate">SET LOG</a>. This problem will be solved
using the new 'page store' mechanism (currently beta).
</p>
<br />
<h3 id="slow_open">Why is Opening my Database Slow?</h3>
......@@ -193,10 +192,10 @@ This is specially a problem for larger databases.
To close a database, close all connections to it before the application ends, or execute
the command <code>SHUTDOWN</code>.
The database is also closed when the virtual machine exits normally
by using a shutdown hook. However killing a Java process or calling Runtime.halt will prevent this.
by using a shutdown hook. However killing a Java process or calling <code>Runtime.halt</code> will prevent this.
The reason why opening is slow in this situations is that indexes are re-created.
If you can not guarantee the database is closed, consider using
<code>SET LOG 2</code> (see SQL Grammar).
<a href="grammar.html#set_log" class="notranslate">SET LOG 2</a>.
</p>
<p>
To find out what the problem is, open the database in embedded mode using the H2 Console.
......
......@@ -118,7 +118,7 @@ Features
</li><li>Many built-in functions, including XML and lossless data compression
</li><li>Wide range of data types including large objects (BLOB/CLOB) and arrays
</li><li>Sequence and autoincrement columns, computed columns (can be used for function based indexes)
</li><li>ORDER BY, GROUP BY, HAVING, UNION, LIMIT, TOP
</li><li><code>ORDER BY, GROUP BY, HAVING, UNION, LIMIT, TOP</code>
</li><li>Collation support, users, roles
</li><li>Compatibility modes for IBM DB2, Apache Derby, HSQLDB,
MS SQL Server, MySQL, Oracle, and PostgreSQL.
......@@ -145,7 +145,7 @@ encrypted using AES-256 and XTEA encryption algorithms
</li><li>Support for multi-dimensional indexes
</li><li>CSV (comma separated values) file support
</li><li>Support for linked tables, and a built-in virtual 'range' table
</li><li>EXPLAIN PLAN support, sophisticated trace options
</li><li><code>EXPLAIN PLAN</code> support, sophisticated trace options
</li><li>Database closing can be delayed or disabled to improve the performance
</li><li>Web-based Console application (translated to many languages) with autocomplete
</li><li>The database can generate SQL script files
......@@ -720,7 +720,7 @@ For more information about the algorithms, see
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 databases, and only allow to open
existing databases. To do this, add <code>;ifexists=true</code>
existing databases. To do this, add <code>;IFEXISTS=TRUE</code>
to the database 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:
......@@ -779,7 +779,7 @@ In some situations, for example when using very large databases (over a few hund
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 <code>jdbc:h2:~/test;LOG=2</code>.
To enable log index changes, add <code>LOG=2</code> to the URL, as in <code>jdbc:h2:~/test;LOG=2</code>.
This setting should be specified when connecting.
The update performance of the database will be reduced when using this option.
</p>
......@@ -1438,7 +1438,7 @@ 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.
in <code>TestMultiDimension.java</code>.
</p>
<br />
......@@ -1452,24 +1452,24 @@ 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><p>
i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
<code>i'sE2rtPiUKtT</code> from the sentence <code>it's easy to remember this password if you know the trick</code>.
</p>
<h3>Passwords: Using Char Arrays instead of Strings</h3>
<p>
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
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><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.
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><p>
This database supports using char arrays instead of String to pass user and file passwords.
This database supports using char arrays instead of string to pass user and file passwords.
The following code can be used to do that:
</p>
<pre>
......
......@@ -89,7 +89,7 @@ Result Sets
Limiting the Number of Rows
@advanced_1030_p
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 <code>LIMIT</code> in a query (example: <code>SELECT * FROM TEST LIMIT 100</code> ), or by using Statement.setMaxRows(max).
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 <code>LIMIT</code> in a query (example: <code>SELECT * FROM TEST LIMIT 100</code> ), or by using <code>Statement.setMaxRows(max)</code> .
@advanced_1031_h3
Large Result Sets and External Sorting
......@@ -104,7 +104,7 @@ Large Objects
Storing and Reading Large Objects
@advanced_1035_p
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. When using the client/server mode, large BLOB and CLOB data is stored in a temporary file on the client side.
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 <code>PreparedStatement.setBinaryStream</code> . To store a CLOB, use <code>PreparedStatement.setCharacterStream</code> . To read a BLOB, use <code>ResultSet.getBinaryStream</code> , and to read a CLOB, use <code>ResultSet.getCharacterStream</code> . When using the client/server mode, large BLOB and CLOB data is stored in a temporary file on the client side.
@advanced_1036_h3
When to use CLOB/BLOB
......@@ -134,13 +134,13 @@ To view the statements that are executed against the target table, set the trace
If multiple linked tables point to the same database (using the same database URL), the connection is shared. To disable this, set the system property <code>h2.shareLinkedConnections=false</code> .
@advanced_1045_p
The <code>CREATE LINKED TABLE</code> statement supports an optional schema name parameter. See the grammar for details.
The statement <a href="grammar.html#create_linked_table" class="notranslate" >CREATE LINKED TABLE</a> supports an optional schema name parameter.
@advanced_1046_h2
Transaction Isolation
@advanced_1047_p
Transaction isolation is provided for all data manipulation language (DML) statements. Most data definition language (DDL) statements commit the current transaction. See the <a href="grammar.html">grammar</a> for details.
Transaction isolation is provided for all data manipulation language (DML) statements. Most data definition language (DDL) statements commit the current transaction. See the <a href="grammar.html">Grammar</a> for details.
@advanced_1048_p
This database supports the following transaction isolation levels:
......@@ -398,7 +398,7 @@ To use the PostgreSQL ODBC driver on 64 bit versions of Windows, first run <code
ODBC Installation
@advanced_1133_p
First, the ODBC driver must be installed. Any recent PostgreSQL ODBC driver should work, however version 8.2 (psqlodbc-08_02*) or newer is recommended. The Windows version of the PostgreSQL ODBC driver is available at <a href="http://www.postgresql.org/ftp/odbc/versions/msi">http://www.postgresql.org/ftp/odbc/versions/msi</a> .
First, the ODBC driver must be installed. Any recent PostgreSQL ODBC driver should work, however version 8.2 ( <code>psqlodbc-08_02*</code> ) or newer is recommended. The Windows version of the PostgreSQL ODBC driver is available at <a href="http://www.postgresql.org/ftp/odbc/versions/msi">http://www.postgresql.org/ftp/odbc/versions/msi</a> .
@advanced_1134_h3
Starting the Server
......@@ -407,7 +407,7 @@ Starting the Server
After installing the ODBC driver, start the H2 Server using the command line:
@advanced_1136_p
The PG Server (PG for PostgreSQL protocol) is started as well. By default, databases are stored in the current working directory where the server is started. Use -baseDir to save databases in another directory, for example the user home directory:
The PG Server (PG for PostgreSQL protocol) is started as well. By default, databases are stored in the current working directory where the server is started. Use <code>-baseDir</code> to save databases in another directory, for example the user home directory:
@advanced_1137_p
The PG server can be started and stopped from within a Java application as follows:
......@@ -551,19 +551,19 @@ Install the .NET Framework from <a href="http://www.microsoft.com">Microsoft</a>
Install <a href="http://www.ikvm.net">IKVM.NET</a> .
@advanced_1184_li
Copy the h2*.jar file to ikvm/bin
Copy the <code>h2*.jar</code> file to <code>ikvm/bin</code>
@advanced_1185_li
Run the H2 Console using: <code>ikvm -jar h2*.jar</code>
@advanced_1186_li
Convert the H2 Console to an .exe file using: <code>ikvmc -target:winexe h2*.jar</code> . You may ignore the warnings.
Convert the H2 Console to an <code>.exe</code> file using: <code>ikvmc -target:winexe h2*.jar</code> . You may ignore the warnings.
@advanced_1187_li
Create a .dll file using (change the version accordingly): <code>ikvmc.exe -target:library -version:1.0.69.0 h2*.jar</code>
Create a <code>.dll</code> file using (change the version accordingly): <code>ikvmc.exe -target:library -version:1.0.69.0 h2*.jar</code>
@advanced_1188_p
If you want your C# application use H2, you need to add the h2.dll and the IKVM.OpenJDK.ClassLibrary.dll to your C# solution. Here some sample code:
If you want your C# application use H2, you need to add the <code>h2.dll</code> and the <code>IKVM.OpenJDK.ClassLibrary.dll</code> to your C# solution. Here some sample code:
@advanced_1189_h2
ACID
......@@ -617,7 +617,7 @@ Complete durability means all committed transaction survive a power failure. Som
Ways to (Not) Achieve Durability
@advanced_1206_p
Making sure that committed transactions are not lost is more complicated than it seems first. To guarantee complete durability, a database must ensure that the log record is on the hard drive before the commit call returns. To do that, databases use different methods. One is to use the 'synchronous write' file access mode. In Java, <code>RandomAccessFile</code> supports the modes <code>"rws"</code> and <code>"rwd"</code> :
Making sure that committed transactions are not lost is more complicated than it seems first. To guarantee complete durability, a database must ensure that the log record is on the hard drive before the commit call returns. To do that, databases use different methods. One is to use the 'synchronous write' file access mode. In Java, <code>RandomAccessFile</code> supports the modes <code>rws</code> and <code>rwd</code> :
@advanced_1207_code
rwd
......@@ -635,13 +635,13 @@ rws
A test ( <code>org.h2.test.poweroff.TestWrite</code> ) with one of those modes achieves around 50 thousand write operations per second. Even when the operating system write buffer is disabled, the write rate is around 50 thousand operations per second. This feature does not force changes to disk because it does not flush all buffers. The test updates the same byte in the file again and again. If the hard drive was able to write at this rate, then the disk would need to make at least 50 thousand revolutions per second, or 3 million RPM (revolutions per minute). There are no such hard drives. The hard drive used for the test is about 7200 RPM, or about 120 revolutions per second. There is an overhead, so the maximum write rate must be lower than that.
@advanced_1212_p
Calling fsync flushes the buffers. There are two ways to do that in Java:
Calling <code>fsync</code> flushes the buffers. There are two ways to do that in Java:
@advanced_1213_code
FileDescriptor.sync()
@advanced_1214_li
. The documentation says that this forces 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 FileDescriptor have been written to the physical medium.
. The documentation says that this forces all system buffers to synchronize with the underlying device. This method is supposed to return after all in-memory modified copies of buffers associated with this file descriptor have been written to the physical medium.
@advanced_1215_code
FileChannel.force()
......@@ -650,7 +650,7 @@ 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.
@advanced_1217_p
By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations per second can be achieved, which is consistent with the RPM rate of the hard drive used. Unfortunately, even when calling <code>FileDescriptor.sync()</code> or <code>FileChannel.force()</code> , data is not always persisted to the hard drive, because most hard drives do not obey fsync(): see <a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a> . In Mac OS X, fsync does not flush hard drive buffers. See <a href="http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html">Bad fsync?</a> . So the situation is confusing, and tests prove there is a problem.
By default, MySQL calls <code>fsync</code> for each commit. When using one of those methods, only around 60 write operations per second can be achieved, which is consistent with the RPM rate of the hard drive used. Unfortunately, even when calling <code>FileDescriptor.sync()</code> or <code>FileChannel.force()</code> , data is not always persisted to the hard drive, because most hard drives do not obey <code>fsync()</code> : see <a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a> . In Mac OS X, <code>fsync</code> does not flush hard drive buffers. See <a href="http://lists.apple.com/archives/darwin-dev/2005/Feb/msg00072.html">Bad fsync?</a> . So the situation is confusing, and tests prove there is a problem.
@advanced_1218_p
Trying to flush hard drive buffers is hard, and if you do the performance is very bad. First you need to make sure that the hard drive actually flushes all buffers. Tests show that this can not be done in a reliable way. Then the maximum number of transactions is around 60 per second. Because of those reasons, the default behavior of H2 is to delay writing committed transactions.
......@@ -692,7 +692,7 @@ File Locking Method 'File'
The default method for database file locking is the 'File Method'. The algorithm is:
@advanced_1231_li
If the lock file does not exist, it is created (using the atomic operation <code>File.createNewFile</code> ). 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 one process deletes the lock file just after another one create it, and a third process creates the file again. It does not occur if there are only two writers.
If the lock file does not exist, it is created (using the atomic operation <code>File.createNewFile</code> ). Then, the process waits a little bit (20 ms) and checks the file again. If the file was changed during this time, the operation is aborted. This protects against a race condition when one process deletes the lock file just after another one create it, and a third process creates the file again. It does not occur if there are only two writers.
@advanced_1232_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.
......@@ -734,7 +734,7 @@ This database engine provides a solution for the security vulnerability known as
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: <code>' OR ''='</code> . In this case the statement becomes:
@advanced_1245_p
Which is always true no matter what the password stored in the database is. For more information about SQL Injection, see Glossary and Links.
Which is always true no matter what the password stored in the database is. For more information about SQL Injection, see <a href="#glossary_links">Glossary and Links</a> .
@advanced_1246_h3
Disabling Literals
......@@ -776,7 +776,7 @@ Restricting Class Loading and Usage
By default there is no restriction on loading classes and executing Java code for admins. That means an admin may call system functions such as <code>System.setProperty</code> by executing:
@advanced_1259_p
To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property <code>h2.allowedClasses</code> in the form of a comma separated list of classes or patterns (items ending with '*'). By default all classes are allowed. Example:
To restrict users (including admins) from loading classes and executing code, the list of allowed classes can be set in the system property <code>h2.allowedClasses</code> in the form of a comma separated list of classes or patterns (items ending with <code>*</code> ). By default all classes are allowed. Example:
@advanced_1260_p
This mechanism is used for all user classes, including database event listeners, trigger classes, user-defined functions, user-defined aggregate functions, and JDBC driver classes (with the exception of the H2 driver) when using the H2 Console.
......@@ -806,7 +806,7 @@ File Encryption
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.
@advanced_1269_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.
When a user tries to connect to an encrypted database, the combination of <code>file@</code> and the file password is hashed using SHA-256. This hash value is transmitted to the server.
@advanced_1270_p
When a new database file is created, a new cryptographically secure random salt value is generated. The size of the salt is 64 bits. 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.
......@@ -1157,13 +1157,13 @@ You need to install a JDK, for example the Sun JDK version 1.5 or 1.6. Ensure th
For Linux and OS X, use <code>./build.sh</code> instead of <code>build</code> .
@build_1027_p
You will get a list of targets. If you want to build the jar file, execute (Windows):
You will get a list of targets. If you want to build the <code>jar</code> file, execute (Windows):
@build_1028_h3
Switching the Source Code
@build_1029_p
By default the source code uses Java 1.5 features, however Java 1.6 is supported as well. To switch the source code to the install version of Java, run:
By default the source code uses Java 1.5 features, however Java 1.6 is supported as well. To switch the source code to the installed version of Java, run:
@build_1030_h2
Build Targets
......@@ -1208,13 +1208,13 @@ Using a Central Repository
You can include the database in your Maven 2 project as a dependency. Example:
@build_1044_p
New versions of this database are first uploaded to http://hsql.sourceforge.net/m2-repo/ and then automatically synchronized with the main maven repository; however after a new release it may take a few hours before they are available there.
New versions of this database are first uploaded to http://hsql.sourceforge.net/m2-repo/ and then automatically synchronized with the main Maven repository; however after a new release it may take a few hours before they are available there.
@build_1045_h3
Using Snapshot Version
@build_1046_p
To build a 'snapshot' H2 jar file and upload it the to the local Maven 2 repository, execute the following command:
To build a <code>h2-*-SNAPSHOT.jar</code> file and upload it the to the local Maven 2 repository, execute the following command:
@build_1047_p
Afterwards, you can include the database in your Maven 2 project as a dependency:
......@@ -1244,7 +1244,7 @@ Providing Patches
If you like to provide patches, please consider the following guidelines to simplify merging them:
@build_1056_li
Only use Java 1.5 features (do not use Java 1.6) (see Environment).
Only use Java 1.5 features (do not use Java 1.6) (see <a href="#environment">Environment</a> ).
@build_1057_li
Follow the coding style used in the project, and use Checkstyle (see above) to verify. For example, do not use tabs (use spaces instead). The checkstyle configuration is in <code>src/installer/checkstyle.xml</code> .
......@@ -1262,7 +1262,7 @@ Verify that you did not break other features: run the test cases by executing <c
Provide end user documentation if required ( <code>src/docsrc/html/*</code> ).
@build_1062_li
Document grammar changes in <code>src/main/org/h2/res/help.csv</code>
Document grammar changes in <code>src/docsrc/help/help.csv</code>
@build_1063_li
Provide a change log entry ( <code>src/docsrc/html/changelog.html</code> ).
......@@ -1271,7 +1271,7 @@ Provide a change log entry ( <code>src/docsrc/html/changelog.html</code> ).
Verify the spelling using <code>build spellcheck</code> . If required add the new words to <code>src/tools/org/h2/build/doc/dictionary.txt</code> .
@build_1065_li
Run the <code>src/installer/buildRelease</code> to find and fix formatting errors.
Run <code>src/installer/buildRelease</code> to find and fix formatting errors.
@build_1066_li
Verify the formatting using <code>build docs</code> and <code>build javadoc</code> .
......@@ -2573,7 +2573,7 @@ Are there Known Bugs? When is the Next Release?
Usually, bugs get fixes as they are found. There is a release every few weeks. Here is the list of known and confirmed issues:
@faq_1014_li
Tomcat and Glassfish 3 set most static fields (final or non-final) to <code>null</code> when unloading a web application. This can cause a <code>NullPointerException</code> in H2 versions 1.1.107 and older, and may still not work in newer versions. Please report it if you run into this issue. In Tomcat >= 6.0 this behavior can be disabled by setting the system property <code>org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES</code> to false, however Tomcat may then run out of memory. A known workaround is to put the h2.jar file in a shared <code>lib</code> directory ( <code>common/lib</code> ).
Tomcat and Glassfish 3 set most static fields (final or non-final) to <code>null</code> when unloading a web application. This can cause a <code>NullPointerException</code> in H2 versions 1.1.107 and older, and may still not work in newer versions. Please report it if you run into this issue. In Tomcat >= 6.0 this behavior can be disabled by setting the system property <code>org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false</code> , however Tomcat may then run out of memory. A known workaround is to put the <code>h2*.jar</code> file in a shared <code>lib</code> directory ( <code>common/lib</code> ).
@faq_1015_li
Some problems have been found with right outer join. Internally, it is converted to left outer join, which does not always produce the same results as other databases when used in combination with other joins.
......@@ -2621,7 +2621,7 @@ The database driver is <code>org.h2.Driver</code> , and the database URL starts
Where are the Database Files Stored?
@faq_1030_p
When using database URLs like <code>jdbc:h2:~/test</code> , the database is stored in the user directory. For Windows, this is usually C:\Documents and Settings\&lt;userName&gt;. If the base directory is not set (as in <code>jdbc:h2:test</code> ), 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 "&lt;Installation Directory&gt;/bin". The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL <code>jdbc:h2:file:data/sample</code> , the database is stored in the directory <code>data</code> (relative to the current working directory). The directory is created automatically if it does not yet exist. It is also possible to use the fully qualified directory name (and for Windows, drive name). Example: <code>jdbc:h2:file:C:/data/test</code>
When using database URLs like <code>jdbc:h2:~/test</code> , the database is stored in the user directory. For Windows, this is usually <code>C:\Documents and Settings\&lt;userName&gt;</code> . If the base directory is not set (as in <code>jdbc:h2:test</code> ), 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 <code>&lt;Installation Directory&gt;/bin</code> . The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL <code>jdbc:h2:file:data/sample</code> , the database is stored in the directory <code>data</code> (relative to the current working directory). The directory is created automatically if it does not yet exist. It is also possible to use the fully qualified directory name (and for Windows, drive name). Example: <code>jdbc:h2:file:C:/data/test</code>
@faq_1031_h3
What is the Size Limit (Maximum Size) of a Database?
......@@ -2633,73 +2633,73 @@ See <a href="advanced.html#limits_limitations">Limits and Limitations</a> .
Is it Reliable?
@faq_1034_p
Some users have reported that after a power failure, the database can sometimes not be opened because the index file is corrupt. In that case, the index file can be deleted (it is automatically re-created). To avoid this, append <code>;LOG=2</code> to the database URL. See also: <a href="grammar.html#set_log" class="notranslate">SET LOG</a> . This problem will be solved using the new 'page store' mechanism (currently beta).
@faq_1035_p
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 there are probably still bugs that have not yet been found (as with most software). Some features are known to be dangerous, they are only supported for situations where performance is more important than reliability. Those dangerous features are:
@faq_1036_li
@faq_1035_li
Disabling the transaction log mechanism using <code>SET LOG 0</code> .
@faq_1037_li
@faq_1036_li
Using the transaction isolation level <code>READ_UNCOMMITTED</code> ( <code>LOCK_MODE 0</code> ) while at the same time using multiple connections.
@faq_1038_li
@faq_1037_li
Disabling database file protection using <code>FILE_LOCK=NO</code> in the database URL.
@faq_1039_li
@faq_1038_li
Disabling referential integrity using <code>SET REFERENTIAL_INTEGRITY FALSE</code> .
@faq_1040_p
@faq_1039_p
In addition to that, running out of memory should be avoided. In older versions, OutOfMemory errors while using the database could corrupt a databases.
@faq_1041_p
@faq_1040_p
Areas that are not fully tested:
@faq_1042_li
@faq_1041_li
Platforms other than Windows XP, Linux, Mac OS X, or JVMs other than Sun 1.5 or 1.6
@faq_1043_li
@faq_1042_li
The features <code>AUTO_SERVER</code> and <code>AUTO_RECONNECT</code>
@faq_1044_li
@faq_1043_li
The MVCC (multi version concurrency) mode
@faq_1045_li
@faq_1044_li
Cluster mode, 2-phase commit, savepoints
@faq_1046_li
@faq_1045_li
24/7 operation
@faq_1047_li
@faq_1046_li
Some operations on databases larger than 500 MB may be slower than expected
@faq_1048_li
@faq_1047_li
The optimizer may not always select the best plan
@faq_1049_li
@faq_1048_li
Fulltext search
@faq_1050_li
@faq_1049_li
Operations on LOBs over 2 GB
@faq_1051_p
@faq_1050_p
Areas considered experimental are:
@faq_1052_li
@faq_1051_li
The PostgreSQL server
@faq_1053_li
@faq_1052_li
Multi-threading within the engine using <code>SET MULTI_THREADED=1</code>
@faq_1054_li
@faq_1053_li
Compatibility modes for other databases (only some features are implemented)
@faq_1054_p
Some users have reported that after a power failure, the database can sometimes not be opened because the index file is corrupt. In that case, the index file can be deleted (it is automatically re-created). To avoid this, append <code>;LOG=2</code> to the database URL. See also: <a href="grammar.html#set_log" class="notranslate">SET LOG</a> . This problem will be solved using the new 'page store' mechanism (currently beta).
@faq_1055_h3
Why is Opening my Database Slow?
@faq_1056_p
If it takes a long time to open a database, in most cases it was not closed the last time. This is specially a problem for larger databases. To close a database, close all connections to it before the application ends, or execute the command <code>SHUTDOWN</code> . The database is also closed when the virtual machine exits normally by using a shutdown hook. However killing a Java process or calling Runtime.halt will prevent this. The reason why opening is slow in this situations is that indexes are re-created. If you can not guarantee the database is closed, consider using <code>SET LOG 2</code> (see SQL Grammar).
If it takes a long time to open a database, in most cases it was not closed the last time. This is specially a problem for larger databases. To close a database, close all connections to it before the application ends, or execute the command <code>SHUTDOWN</code> . The database is also closed when the virtual machine exits normally by using a shutdown hook. However killing a Java process or calling <code>Runtime.halt</code> will prevent this. The reason why opening is slow in this situations is that indexes are re-created. If you can not guarantee the database is closed, consider using <a href="grammar.html#set_log" class="notranslate">SET LOG 2</a> .
@faq_1057_p
To find out what the problem is, open the database in embedded mode using the H2 Console. This will print progress information. If you have many lines with 'Creating index' it is an indication that the database was not closed the last time.
......@@ -2896,7 +2896,7 @@ Wide range of data types including large objects (BLOB/CLOB) and arrays
@features_1058_li
Sequence and autoincrement columns, computed columns (can be used for function based indexes)
@features_1059_li
@features_1059_code
ORDER BY, GROUP BY, HAVING, UNION, LIMIT, TOP
@features_1060_li
......@@ -2947,62 +2947,62 @@ CSV (comma separated values) file support
@features_1075_li
Support for linked tables, and a built-in virtual 'range' table
@features_1076_li
EXPLAIN PLAN support, sophisticated trace options
@features_1076_code
EXPLAIN PLAN
@features_1077_li
Database closing can be delayed or disabled to improve the performance
support, sophisticated trace options
@features_1078_li
Web-based Console application (translated to many languages) with autocomplete
Database closing can be delayed or disabled to improve the performance
@features_1079_li
The database can generate SQL script files
Web-based Console application (translated to many languages) with autocomplete
@features_1080_li
Contains a recovery tool that can dump the contents of the database
The database can generate SQL script files
@features_1081_li
Support for variables (for example to calculate running totals)
Contains a recovery tool that can dump the contents of the database
@features_1082_li
Automatic re-compilation of prepared statements
Support for variables (for example to calculate running totals)
@features_1083_li
Uses a small number of database files
Automatic re-compilation of prepared statements
@features_1084_li
Uses a checksum for each record and log entry for data integrity
Uses a small number of database files
@features_1085_li
Uses a checksum for each record and log entry for data integrity
@features_1086_li
Well tested (high code coverage, randomized stress tests)
@features_1086_h2
@features_1087_h2
Comparison to Other Database Engines
@features_1087_th
@features_1088_th
Feature
@features_1088_th
@features_1089_th
H2
@features_1089_a
@features_1090_a
Derby
@features_1090_a
@features_1091_a
HSQLDB
@features_1091_a
@features_1092_a
MySQL
@features_1092_a
@features_1093_a
PostgreSQL
@features_1093_td
Pure Java
@features_1094_td
Yes
Pure Java
@features_1095_td
Yes
......@@ -3011,16 +3011,16 @@ Yes
Yes
@features_1097_td
No
Yes
@features_1098_td
No
@features_1099_td
Embedded Mode (Java)
No
@features_1100_td
Yes
Embedded Mode (Java)
@features_1101_td
Yes
......@@ -3029,94 +3029,94 @@ Yes
Yes
@features_1103_td
No
Yes
@features_1104_td
No
@features_1105_td
Performance (Embedded)
No
@features_1106_td
Fast
Performance (Embedded)
@features_1107_td
Slow
Fast
@features_1108_td
Fast
Slow
@features_1109_td
N/A
Fast
@features_1110_td
N/A
@features_1111_td
In-Memory Mode
N/A
@features_1112_td
Yes
In-Memory Mode
@features_1113_td
No
Yes
@features_1114_td
Yes
No
@features_1115_td
No
Yes
@features_1116_td
No
@features_1117_td
Transaction Isolation
No
@features_1118_td
Yes
Transaction Isolation
@features_1119_td
Yes
@features_1120_td
No
Yes
@features_1121_td
Yes
No
@features_1122_td
Yes
@features_1123_td
Cost Based Optimizer
Yes
@features_1124_td
Yes
Cost Based Optimizer
@features_1125_td
Yes
@features_1126_td
No
Yes
@features_1127_td
Yes
No
@features_1128_td
Yes
@features_1129_td
Explain Plan
Yes
@features_1130_td
Yes
Explain Plan
@features_1131_td
No
Yes
@features_1132_td
Yes
No
@features_1133_td
Yes
......@@ -3125,34 +3125,34 @@ Yes
Yes
@features_1135_td
Clustering
Yes
@features_1136_td
Yes
Clustering
@features_1137_td
No
Yes
@features_1138_td
No
@features_1139_td
Yes
No
@features_1140_td
Yes
@features_1141_td
Encrypted Database
Yes
@features_1142_td
Yes
Encrypted Database
@features_1143_td
Yes
@features_1144_td
No
Yes
@features_1145_td
No
......@@ -3161,139 +3161,139 @@ No
No
@features_1147_td
Linked Tables
No
@features_1148_td
Yes
Linked Tables
@features_1149_td
No
Yes
@features_1150_td
Partially *1
No
@features_1151_td
Partially *2
Partially *1
@features_1152_td
No
Partially *2
@features_1153_td
ODBC Driver
No
@features_1154_td
Yes
ODBC Driver
@features_1155_td
No
Yes
@features_1156_td
No
@features_1157_td
Yes
No
@features_1158_td
Yes
@features_1159_td
Fulltext Search
Yes
@features_1160_td
Yes
Fulltext Search
@features_1161_td
No
Yes
@features_1162_td
No
@features_1163_td
Yes
No
@features_1164_td
Yes
@features_1165_td
User-Defined Datatypes
Yes
@features_1166_td
Yes
User-Defined Datatypes
@features_1167_td
No
Yes
@features_1168_td
No
@features_1169_td
Yes
No
@features_1170_td
Yes
@features_1171_td
Files per Database
Yes
@features_1172_td
Few
Files per Database
@features_1173_td
Many
Few
@features_1174_td
Few
Many
@features_1175_td
Many
Few
@features_1176_td
Many
@features_1177_td
Table Level Locking
Many
@features_1178_td
Yes
Table Level Locking
@features_1179_td
Yes
@features_1180_td
No
Yes
@features_1181_td
Yes
No
@features_1182_td
Yes
@features_1183_td
Row Level Locking
Yes
@features_1184_td
Yes *9
Row Level Locking
@features_1185_td
Yes
Yes *9
@features_1186_td
No
Yes
@features_1187_td
Yes
No
@features_1188_td
Yes
@features_1189_td
Multi Version Concurrency
Yes
@features_1190_td
Yes
Multi Version Concurrency
@features_1191_td
No
Yes
@features_1192_td
No
......@@ -3302,19 +3302,19 @@ No
No
@features_1194_td
Yes
No
@features_1195_td
Role Based Security
Yes
@features_1196_td
Yes
Role Based Security
@features_1197_td
Yes *3
Yes
@features_1198_td
Yes
Yes *3
@features_1199_td
Yes
......@@ -3323,52 +3323,52 @@ Yes
Yes
@features_1201_td
Updatable Result Sets
Yes
@features_1202_td
Yes
Updatable Result Sets
@features_1203_td
Yes *7
Yes
@features_1204_td
No
Yes *7
@features_1205_td
Yes
No
@features_1206_td
Yes
@features_1207_td
Sequences
Yes
@features_1208_td
Yes
Sequences
@features_1209_td
No
Yes
@features_1210_td
Yes
No
@features_1211_td
No
Yes
@features_1212_td
Yes
No
@features_1213_td
Limit and Offset
Yes
@features_1214_td
Yes
Limit and Offset
@features_1215_td
No
Yes
@features_1216_td
Yes
No
@features_1217_td
Yes
......@@ -3377,16 +3377,16 @@ Yes
Yes
@features_1219_td
Temporary Tables
Yes
@features_1220_td
Yes
Temporary Tables
@features_1221_td
Yes *4
Yes
@features_1222_td
Yes
Yes *4
@features_1223_td
Yes
......@@ -3395,31 +3395,31 @@ Yes
Yes
@features_1225_td
Information Schema
Yes
@features_1226_td
Yes
Information Schema
@features_1227_td
No *8
Yes
@features_1228_td
No *8
@features_1229_td
Yes
No *8
@features_1230_td
Yes
@features_1231_td
Computed Columns
@features_1232_td
Yes
@features_1232_td
Computed Columns
@features_1233_td
No
Yes
@features_1234_td
No
......@@ -3428,1116 +3428,1122 @@ No
No
@features_1236_td
Yes *6
No
@features_1237_td
Case Insensitive Columns
Yes *6
@features_1238_td
Yes
Case Insensitive Columns
@features_1239_td
No
Yes
@features_1240_td
Yes
No
@features_1241_td
Yes
@features_1242_td
Yes *6
Yes
@features_1243_td
Custom Aggregate Functions
Yes *6
@features_1244_td
Yes
Custom Aggregate Functions
@features_1245_td
No
Yes
@features_1246_td
No
@features_1247_td
Yes
No
@features_1248_td
Yes
@features_1249_td
Footprint (jar/dll size)
Yes
@features_1250_td
~1 MB *5
Footprint (jar/dll size)
@features_1251_td
~2 MB
~1 MB *5
@features_1252_td
~700 KB
~2 MB
@features_1253_td
~4 MB
~700 KB
@features_1254_td
~4 MB
@features_1255_td
~6 MB
@features_1255_p
@features_1256_p
*1 HSQLDB supports text tables.
@features_1256_p
@features_1257_p
*2 MySQL supports linked MySQL tables under the name 'federated tables'.
@features_1257_p
@features_1258_p
*3 Derby support for roles based security and password checking as an option.
@features_1258_p
@features_1259_p
*4 Derby only supports global temporary tables.
@features_1259_p
@features_1260_p
*5 The default H2 jar file contains debug information, jar files for other databases do not.
@features_1260_p
@features_1261_p
*6 PostgreSQL supports functional indexes.
@features_1261_p
@features_1262_p
*7 Derby only supports updatable result sets if the query is not sorted.
@features_1262_p
@features_1263_p
*8 Derby and HSQLDB don't support standard compliant information schema tables.
@features_1263_p
@features_1264_p
*9 H2 supports row level locks when using multi version concurrency.
@features_1264_h3
@features_1265_h3
Derby and HSQLDB
@features_1265_p
@features_1266_p
After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
@features_1266_h3
@features_1267_h3
DaffodilDb and One$Db
@features_1267_p
@features_1268_p
It looks like the development of this database has stopped. The last release was February 2006.
@features_1268_h3
@features_1269_h3
McKoi
@features_1269_p
@features_1270_p
It looks like the development of this database has stopped. The last release was August 2004
@features_1270_h2
@features_1271_h2
H2 in Use
@features_1271_p
@features_1272_p
For a list of applications that work with or use H2, see: <a href="links.html">Links</a> .
@features_1272_h2
@features_1273_h2
Connection Modes
@features_1273_p
@features_1274_p
The following connection modes are supported:
@features_1274_li
@features_1275_li
Embedded mode (local connections using JDBC)
@features_1275_li
@features_1276_li
Server mode (remote connections using JDBC or ODBC over TCP/IP)
@features_1276_li
@features_1277_li
Mixed mode (local and remote connections at the same time)
@features_1277_h3
@features_1278_h3
Embedded Mode
@features_1278_p
@features_1279_p
In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1279_h3
@features_1280_h3
Server Mode
@features_1280_p
@features_1281_p
When using the server mode (sometimes called remote mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine, or on another computer. Many applications can connect to the same database at the same time. The server mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1281_h3
@features_1282_h3
Mixed Mode
@features_1282_p
@features_1283_p
The mixed mode is a combination of the embedded and the server mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The local connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower.
@features_1283_p
@features_1284_p
The server can be started and stopped from within the application (using the server API), or automatically (automatic mixed mode). When using the <a href="#auto_mixed_mode">automatic mixed mode</a> , all clients that want to connect to the database (no matter if it's an local or remote connection) can do so using the exact same database URL.
@features_1284_h2
@features_1285_h2
Database URL Overview
@features_1285_p
@features_1286_p
This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
@features_1286_th
@features_1287_th
Topic
@features_1287_th
@features_1288_th
URL Format and Examples
@features_1288_a
@features_1289_a
Embedded (local) connection
@features_1289_td
@features_1290_td
jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;
@features_1290_td
@features_1291_td
jdbc:h2:~/test
@features_1291_td
@features_1292_td
jdbc:h2:file:/data/sample
@features_1292_td
@features_1293_td
jdbc:h2:file:C:/data/sample (Windows only)
@features_1293_a
@features_1294_a
In-memory (private)
@features_1294_td
@features_1295_td
jdbc:h2:mem:
@features_1295_a
@features_1296_a
In-memory (named)
@features_1296_td
@features_1297_td
jdbc:h2:mem:&lt;databaseName&gt;
@features_1297_td
@features_1298_td
jdbc:h2:mem:test_mem
@features_1298_a
@features_1299_a
Server mode (remote connections)
@features_1299_a
@features_1300_a
using TCP/IP
@features_1300_td
@features_1301_td
jdbc:h2:tcp://&lt;server&gt;[:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt;
@features_1301_td
@features_1302_td
jdbc:h2:tcp://localhost/~/test
@features_1302_td
@features_1303_td
jdbc:h2:tcp://dbserv:8084/~/sample
@features_1303_a
@features_1304_a
Server mode (remote connections)
@features_1304_a
@features_1305_a
using SSL/TLS
@features_1305_td
@features_1306_td
jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt;
@features_1306_td
@features_1307_td
jdbc:h2:ssl://secureserv:8085/~/sample;
@features_1307_a
@features_1308_a
Using encrypted files
@features_1308_td
@features_1309_td
jdbc:h2:&lt;url&gt;;CIPHER=[AES|XTEA]
@features_1309_td
@features_1310_td
jdbc:h2:ssl://secureserv/~/testdb;CIPHER=AES
@features_1310_td
@features_1311_td
jdbc:h2:file:~/secure;CIPHER=XTEA
@features_1311_a
@features_1312_a
File locking methods
@features_1312_td
@features_1313_td
jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET}
@features_1313_td
@features_1314_td
jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO
@features_1314_td
@features_1315_td
jdbc:h2:file:~/private;CIPHER=XTEA;FILE_LOCK=SOCKET
@features_1315_a
@features_1316_a
Only open if it already exists
@features_1316_td
@features_1317_td
jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE
@features_1317_td
@features_1318_td
jdbc:h2:file:~/sample;IFEXISTS=TRUE
@features_1318_a
@features_1319_a
Don't close the database when the VM exits
@features_1319_td
@features_1320_td
jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE
@features_1320_a
@features_1321_a
User name and/or password
@features_1321_td
@features_1322_td
jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;]
@features_1322_td
@features_1323_td
jdbc:h2:file:~/sample;USER=sa;PASSWORD=123
@features_1323_a
@features_1324_a
Log index changes
@features_1324_td
@features_1325_td
jdbc:h2:&lt;url&gt;;LOG=2
@features_1325_td
@features_1326_td
jdbc:h2:file:~/sample;LOG=2
@features_1326_a
@features_1327_a
Debug trace settings
@features_1327_td
@features_1328_td
jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt;
@features_1328_td
@features_1329_td
jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3
@features_1329_a
@features_1330_a
Ignore unknown settings
@features_1330_td
@features_1331_td
jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE
@features_1331_a
@features_1332_a
Custom file access mode
@features_1332_td
@features_1333_td
jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws
@features_1333_a
@features_1334_a
Database in a zip file
@features_1334_td
@features_1335_td
jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt;
@features_1335_td
@features_1336_td
jdbc:h2:zip:~/db.zip!/test
@features_1336_a
@features_1337_a
Compatibility mode
@features_1337_td
@features_1338_td
jdbc:h2:&lt;url&gt;;MODE=&lt;databaseType&gt;
@features_1338_td
@features_1339_td
jdbc:h2:~/test;MODE=MYSQL
@features_1339_a
@features_1340_a
Auto-reconnect
@features_1340_td
@features_1341_td
jdbc:h2:&lt;url&gt;;AUTO_RECONNECT=TRUE
@features_1341_td
@features_1342_td
jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE
@features_1342_a
@features_1343_a
Automatic mixed mode
@features_1343_td
@features_1344_td
jdbc:h2:&lt;url&gt;;AUTO_SERVER=TRUE
@features_1344_td
@features_1345_td
jdbc:h2:~/test;AUTO_SERVER=TRUE
@features_1345_a
@features_1346_a
Changing other settings
@features_1346_td
@features_1347_td
jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...]
@features_1347_td
@features_1348_td
jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
@features_1348_h2
@features_1349_h2
Connecting to an Embedded (Local) Database
@features_1349_p
@features_1350_p
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 recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of <code>File.createTempFile</code> ). To point to the user home directory, use <code>~/</code> , as in: <code>jdbc:h2:~/test</code> .
@features_1350_h2
@features_1351_h2
Memory-Only Databases
@features_1351_p
@features_1352_p
For certain use cases (for example: rapid prototyping, testing, high performance operations, read-only databases), it may not be required to persist data, or persist changes to the data. This database supports the memory-only mode, where the data is not persisted.
@features_1352_p
@features_1353_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.
@features_1353_p
@features_1354_p
Sometimes 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> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
@features_1354_p
@features_1355_p
It is also possible to access a memory-only database remotely (or from multiple processes in the same machine) using TCP/IP or SSL/TLS. An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code> .
@features_1355_p
@features_1356_p
By default, closing the last connection to a database closes the database. For an in-memory database, this means the content is lost. To keep the database open, add <code>;DB_CLOSE_DELAY=-1</code> to the database URL. To keep the content of an in-memory database as long as the virtual machine is alive, use <code>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</code> .
@features_1356_h2
@features_1357_h2
Database Files Encryption
@features_1357_p
@features_1358_p
The database files can be encrypted. Two encryption algorithms are supported: AES and XTEA. To use file encryption, you need to specify the encryption algorithm (the 'cipher') and the file password (in addition to the user password) when connecting to the database.
@features_1358_h3
@features_1359_h3
Creating a New Database with File Encryption
@features_1359_p
@features_1360_p
By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
@features_1360_h3
@features_1361_h3
Connecting to an Encrypted Database
@features_1361_p
@features_1362_p
The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space separates the file password and the user password; the file password itself may not contain spaces. File passwords and user passwords are case sensitive. Here is an example to connect to a password-encrypted database:
@features_1362_h3
@features_1363_h3
Encrypting or Decrypting a Database
@features_1363_p
@features_1364_p
To encrypt an existing database, use the <code>ChangeFileEncryption</code> tool. This tool can also decrypt an encrypted database, or change the file encryption key. The tool is available from within the H2 Console in the tools section, or you can run it from the command line. The following command line will encrypt the database <code>test</code> in the user home directory with the file password <code>filepwd</code> and the encryption algorithm AES:
@features_1364_h2
@features_1365_h2
Database File Locking
@features_1365_p
@features_1366_p
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.
@features_1366_p
@features_1367_p
The following file locking methods are implemented:
@features_1367_li
@features_1368_li
The default method is 'file' and uses a watchdog thread to protect the database file. The watchdog reads the lock file each second.
@features_1368_li
@features_1369_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 one (and always the same) computer.
@features_1369_li
@features_1370_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.
@features_1370_p
@features_1371_p
To open the database with a different file locking method, use the parameter <code>FILE_LOCK</code> . The following code opens the database with the 'socket' locking method:
@features_1371_p
@features_1372_p
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:
@features_1372_p
@features_1373_p
For more information about the algorithms, see <a href="advanced.html#file_locking_protocols">Advanced / File Locking Protocols</a> .
@features_1373_h2
@features_1374_h2
Opening a Database Only if it Already Exists
@features_1374_p
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 databases, and only allow to open existing databases. To do this, add <code>;ifexists=true</code> to the database 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:
@features_1375_p
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 databases, and only allow to open existing databases. To do this, add <code>;IFEXISTS=TRUE</code> to the database 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:
@features_1375_h2
@features_1376_h2
Closing a Database
@features_1376_h3
@features_1377_h3
Delayed Database Closing
@features_1377_p
@features_1378_p
Usually, a 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 to keep at least one connection open. The automatic closing of a database can be delayed or disabled with the SQL statement <code>SET DB_CLOSE_DELAY &lt;seconds&gt;</code> . The parameter &lt;seconds&gt; specifies the number of seconds to keep a database open after the last connection to it was closed. The following statement will keep a database open for 10 seconds after the last connection was closed:
@features_1378_p
@features_1379_p
The value -1 means the database is not 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> .
@features_1379_h3
@features_1380_h3
Don't Close a Database when the VM Exits
@features_1380_p
@features_1381_p
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, 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). For those cases, the automatic closing of the database can be disabled 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:
@features_1381_h2
@features_1382_h2
Log Index Changes
@features_1382_p
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 <code>jdbc:h2:~/test;LOG=2</code> . This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
@features_1383_p
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 <code>LOG=2</code> to the URL, as in <code>jdbc:h2:~/test;LOG=2</code> . This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
@features_1383_h2
@features_1384_h2
Ignore Unknown Settings
@features_1384_p
@features_1385_p
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 <code>PREFERDOSLIKELINEENDS</code> and <code>IGNOREDRIVERPRIVILEGES</code> 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 <code>;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL.
@features_1385_h2
@features_1386_h2
Changing Other Settings when Opening a Connection
@features_1386_p
@features_1387_p
In addition to the settings already described, other database settings can be passed in the database URL. Adding <code>;setting=value</code> at the end of a database URL is the same as executing the statement <code>SET setting value</code> just after connecting. For a list of supported settings, see <a href="grammar.html">SQL Grammar</a> .
@features_1387_h2
@features_1388_h2
Custom File Access Mode
@features_1388_p
@features_1389_p
Usually, the database opens log, data and index files with the access mode <code>rw</code> , meaning read-write (except for read only databases, where the mode <code>r</code> is used). To open a database in read-only mode if the files are not read-only, use <code>ACCESS_MODE_DATA=r</code> . Also supported are <code>rws</code> and <code>rwd</code> . The access mode used for log files is set via <code>ACCESS_MODE_LOG</code> ; for data and index files use <code>ACCESS_MODE_DATA</code> . These settings must be specified in the database URL:
@features_1389_p
@features_1390_p
For more information see <a href="advanced.html#durability_problems">Durability Problems</a> . On many operating systems the access mode <code>rws</code> does not guarantee that the data is written to the disk.
@features_1390_h2
@features_1391_h2
Multiple Connections
@features_1391_h3
@features_1392_h3
Opening Multiple Databases at the Same Time
@features_1392_p
@features_1393_p
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.
@features_1393_h3
@features_1394_h3
Multiple Connections to the Same Database: Client/Server
@features_1394_p
@features_1395_p
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).
@features_1395_h3
@features_1396_h3
Multithreading Support
@features_1396_p
@features_1397_p
This database is multithreading-safe. That means, if an application is multi-threaded, it does not need to worry about synchronizing access to the database. Internally, most requests to the same database are synchronized. That means an application can use multiple threads that access the same database at the same time, however if one thread executes a long running query, the other threads need to wait.
@features_1397_h3
@features_1398_h3
Locking, Lock-Timeout, Deadlocks
@features_1398_p
@features_1399_p
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). All locks are released when the transaction commits or rolls back. When using the default transaction isolation level 'read committed', read locks are already released after each statement.
@features_1399_p
@features_1400_p
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 a connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
@features_1400_p
@features_1401_p
Usually, <code>SELECT</code> statements 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 <code>SELECT ... FOR UPDATE</code> . The statements <code>COMMIT</code> and <code>ROLLBACK</code> releases all open locks. The commands <code>SAVEPOINT</code> and <code>ROLLBACK TO SAVEPOINT</code> 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. The following statements generate locks:
@features_1401_th
@features_1402_th
Type of Lock
@features_1402_th
@features_1403_th
SQL Statement
@features_1403_td
@features_1404_td
Read
@features_1404_td
@features_1405_td
SELECT * FROM TEST;
@features_1405_td
@features_1406_td
CALL SELECT MAX(ID) FROM TEST;
@features_1406_td
@features_1407_td
SCRIPT;
@features_1407_td
@features_1408_td
Write
@features_1408_td
@features_1409_td
SELECT * FROM TEST WHERE 1=0 FOR UPDATE;
@features_1409_td
@features_1410_td
Write
@features_1410_td
@features_1411_td
INSERT INTO TEST VALUES(1, 'Hello');
@features_1411_td
@features_1412_td
INSERT INTO TEST SELECT * FROM TEST;
@features_1412_td
@features_1413_td
UPDATE TEST SET NAME='Hi';
@features_1413_td
@features_1414_td
DELETE FROM TEST;
@features_1414_td
@features_1415_td
Write
@features_1415_td
@features_1416_td
ALTER TABLE TEST ...;
@features_1416_td
@features_1417_td
CREATE INDEX ... ON TEST ...;
@features_1417_td
@features_1418_td
DROP INDEX ...;
@features_1418_p
@features_1419_p
The number of seconds until a lock timeout exception is thrown can be set separately for each connection using the SQL command <code>SET LOCK_TIMEOUT &lt;milliseconds&gt;</code> . The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command <code>SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;</code> . The default lock timeout is persistent.
@features_1419_h2
@features_1420_h2
Database File Layout
@features_1420_p
@features_1421_p
There are a number of files created for persistent databases. Unlike some other 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) larger than a certain size, and temporary files for large result sets. If the database trace option is enabled, trace files are created. The following files can be created by the database:
@features_1421_th
@features_1422_th
File Name
@features_1422_th
@features_1423_th
Description
@features_1423_th
@features_1424_th
Number of Files
@features_1424_td
@features_1425_td
test.h2.db
@features_1425_td
@features_1426_td
Database file.
@features_1426_td
@features_1427_td
Contains the data and index data for all tables.
@features_1427_td
@features_1428_td
Format: <code>&lt;database&gt;.h2.db</code>
@features_1428_td
@features_1429_td
1 per database
@features_1429_td
@features_1430_td
test.data.db
@features_1430_td
@features_1431_td
Data file.
@features_1431_td
@features_1432_td
Contains the data for all tables.
@features_1432_td
@features_1433_td
Format: <code>&lt;database&gt;.data.db</code>
@features_1433_td
@features_1434_td
1 per database
@features_1434_td
@features_1435_td
test.index.db
@features_1435_td
@features_1436_td
Index file.
@features_1436_td
@features_1437_td
Contains the data for all (b tree) indexes.
@features_1437_td
@features_1438_td
Format: <code>&lt;database&gt;.index.db</code>
@features_1438_td
@features_1439_td
1 per database
@features_1439_td
@features_1440_td
test.0.log.db
@features_1440_td
@features_1441_td
Transaction log file.
@features_1441_td
@features_1442_td
The transaction log is used for recovery.
@features_1442_td
@features_1443_td
Format: <code>&lt;database&gt;.&lt;id&gt;.log.db</code>
@features_1443_td
@features_1444_td
0 or more per database
@features_1444_td
@features_1445_td
test.lock.db
@features_1445_td
@features_1446_td
Database lock file.
@features_1446_td
@features_1447_td
Exists only while the database is open.
@features_1447_td
@features_1448_td
Format: <code>&lt;database&gt;.lock.db</code>
@features_1448_td
@features_1449_td
1 per database
@features_1449_td
@features_1450_td
test.trace.db
@features_1450_td
@features_1451_td
Trace file.
@features_1451_td
@features_1452_td
Contains trace information.
@features_1452_td
@features_1453_td
Format: <code>&lt;database&gt;.trace.db</code>
@features_1453_td
@features_1454_td
If the file is too big, it is renamed to <code>&lt;database&gt;.trace.db.old</code>
@features_1454_td
@features_1455_td
1 per database
@features_1455_td
@features_1456_td
test.lobs.db/1.t15.lob.db
@features_1456_td
@features_1457_td
Large object.
@features_1457_td
@features_1458_td
Contains the data for BLOB or CLOB values.
@features_1458_td
@features_1459_td
Format: <code>&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
@features_1459_td
@features_1460_td
1 per value
@features_1460_td
@features_1461_td
test.123.temp.db
@features_1461_td
@features_1462_td
Temporary file.
@features_1462_td
@features_1463_td
Contains a temporary blob or a large result set.
@features_1463_td
@features_1464_td
Format: <code>&lt;database&gt;.&lt;id&gt;.temp.db</code>
@features_1464_td
@features_1465_td
1 per object
@features_1465_h3
@features_1466_h3
Moving and Renaming Database Files
@features_1466_p
@features_1467_p
Database name and location are not stored inside the database files.
@features_1467_p
@features_1468_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).
@features_1468_p
@features_1469_p
As there is no platform specific data in the files, they can be moved to other operating systems without problems.
@features_1469_h3
@features_1470_h3
Backup
@features_1470_p
@features_1471_p
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.
@features_1471_p
@features_1472_p
To backup data while the database is running, the SQL command <code>SCRIPT</code> can be used.
@features_1472_h2
@features_1473_h2
Logging and Recovery
@features_1473_p
@features_1474_p
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.
@features_1474_p
@features_1475_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.
@features_1475_p
@features_1476_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 <code>CHECKPOINT</code> command.
@features_1476_p
@features_1477_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 <code>;RECOVER=1</code> , as in <code>jdbc:h2:~/test;RECOVER=1</code> . Indexes are rebuilt in this case, and the summary (object allocation table) is not read in this case, so opening the database takes longer.
@features_1477_h2
@features_1478_h2
Compatibility
@features_1478_p
@features_1479_p
All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however:
@features_1479_p
@features_1480_p
In MySQL text columns are case insensitive by default, while in H2 they are case sensitive. However H2 supports case insensitive columns as well. To create the tables with case insensitive texts, append <code>IGNORECASE=TRUE</code> to the database URL (example: <code>jdbc:h2:~/test;IGNORECASE=TRUE</code> ).
@features_1480_h3
@features_1481_h3
Compatibility Modes
@features_1481_p
@features_1482_p
For certain features, this database can emulate the behavior of specific databases. Not all features or differences of those databases are implemented. Here is the list of currently supported modes and the differences to the regular mode:
@features_1482_h3
@features_1483_h3
DB2 Compatibility Mode
@features_1483_p
@features_1484_p
To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
@features_1484_li
@features_1485_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1485_li
@features_1486_li
Support for the syntax <code>[OFFSET .. ROW] [FETCH ... ONLY]</code> as an alternative for <code>LIMIT .. OFFSET</code> .
@features_1486_li
@features_1487_li
Concatenating <code>NULL</code> with another value results in the other value.
@features_1487_h3
@features_1488_h3
Derby Compatibility Mode
@features_1488_p
@features_1489_p
To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
@features_1489_li
@features_1490_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1490_li
@features_1491_li
For unique indexes, <code>NULL</code> is distinct. That means only one row with <code>NULL</code> in one of the columns is allowed.
@features_1491_li
@features_1492_li
Concatenating <code>NULL</code> with another value results in the other value.
@features_1492_h3
@features_1493_h3
HSQLDB Compatibility Mode
@features_1493_p
@features_1494_p
To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
@features_1494_li
@features_1495_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1495_li
@features_1496_li
When converting the scale of decimal data, the number is only converted if the new scale is smaller than the current scale. Usually, the scale is converted and 0s are added if required.
@features_1496_li
@features_1497_li
For unique indexes, <code>NULL</code> is distinct. That means only one row with <code>NULL</code> in one of the columns is allowed.
@features_1497_h3
@features_1498_h3
MS SQL Server Compatibility Mode
@features_1498_p
@features_1499_p
To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
@features_1499_li
@features_1500_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1500_li
@features_1501_li
Identifiers may be quoted using square brackets as in <code>[Test]</code> .
@features_1501_li
@features_1502_li
For unique indexes, <code>NULL</code> is distinct. That means only one row with <code>NULL</code> in one of the columns is allowed.
@features_1502_li
@features_1503_li
Concatenating <code>NULL</code> with another value results in the other value.
@features_1503_h3
@features_1504_h3
MySQL Compatibility Mode
@features_1504_p
@features_1505_p
To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
@features_1505_li
@features_1506_li
When inserting data, if a column is defined to be <code>NOT NULL</code> and <code>NULL</code> 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.
@features_1506_li
@features_1507_li
Creating indexes in the <code>CREATE TABLE</code> statement is allowed.
@features_1507_li
@features_1508_li
Meta data calls return identifiers in lower case.
@features_1508_li
@features_1509_li
When converting a floating point number to an integer, the fractional digits are not truncated, but the value is rounded.
@features_1509_li
@features_1510_li
Concatenating <code>NULL</code> with another value results in the other value.
@features_1510_h3
@features_1511_h3
Oracle Compatibility Mode
@features_1511_p
@features_1512_p
To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
@features_1512_li
@features_1513_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1513_li
@features_1514_li
When using unique indexes, multiple rows with <code>NULL</code> in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
@features_1514_li
@features_1515_li
Concatenating <code>NULL</code> with another value results in the other value.
@features_1515_h3
@features_1516_h3
PostgreSQL Compatibility Mode
@features_1516_p
@features_1517_p
To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
@features_1517_li
@features_1518_li
For aliased columns, <code>ResultSetMetaData.getColumnName()</code> returns the alias name and <code>getTableName()</code> returns <code>null</code> .
@features_1518_li
@features_1519_li
When converting a floating point number to an integer, the fractional digits are not be truncated, but the value is rounded.
@features_1519_li
@features_1520_li
The system columns <code>CTID</code> and <code>OID</code> are supported.
@features_1520_h2
@features_1521_h2
Auto-Reconnect
@features_1521_p
@features_1522_p
The auto-reconnect feature causes the JDBC driver to reconnect to the database if the connection is lost. The automatic re-connect only occurs when auto-commit is enabled; if auto-commit is disabled, an exception is thrown.
@features_1522_p
@features_1523_p
Re-connecting will open a new session. After an automatic re-connect, variables and local temporary tables definitions (excluding data) are re-created. The contents of the system table <code>INFORMATION_SCHEMA.SESSION_STATE</code> contains all client side state that is re-created.
@features_1523_h2
@features_1524_h2
Automatic Mixed Mode
@features_1524_p
@features_1525_p
Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
@features_1525_p
@features_1526_p
When using this mode, the first connection to the database is made in embedded mode, and additionally a server is started internally. If the database is already open in another process, the server mode is used automatically.
@features_1526_p
@features_1527_p
The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads <code>.lock.db</code> file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
@features_1527_p
@features_1528_p
All processes need to have access to the database files. If the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Explicit client/server connections (using <code>jdbc:h2:tcp://</code> or <code>ssl://</code> ) are not supported. This mode is not supported for in-memory databases.
@features_1528_p
@features_1529_p
Here is an example how to use this mode. Application 1 and 2 are not necessarily started on the same computer, but they need to have access to the database files. Application 1 and 2 are typically two different processes (however they could run within the same process).
@features_1529_h2
@features_1530_h2
Using the Trace Options
@features_1530_p
@features_1531_p
To find problems in an application, it is sometimes good to see what database operations where executed. This database offers the following trace features:
@features_1531_li
@features_1532_li
Trace to <code>System.out</code> and/or to a file
@features_1532_li
@features_1533_li
Support for trace levels <code>OFF, ERROR, INFO, DEBUG</code>
@features_1533_li
@features_1534_li
The maximum size of the trace file can be set
@features_1534_li
@features_1535_li
It is possible to generate Java source code from the trace file
@features_1535_li
@features_1536_li
Trace can be enabled at runtime by manually creating a file
@features_1536_h3
@features_1537_h3
Trace Options
@features_1537_p
@features_1538_p
The simplest way to enable the trace option is setting it in the database URL. There are two settings, one for <code>System.out</code> ( <code>TRACE_LEVEL_SYSTEM_OUT</code> ) tracing, and one for file tracing ( <code>TRACE_LEVEL_FILE</code> ). The trace levels are 0 for <code>OFF</code> , 1 for <code>ERROR</code> (the default), 2 for <code>INFO</code> , and 3 for <code>DEBUG</code> . A database URL with both levels set to <code>DEBUG</code> is:
@features_1538_p
@features_1539_p
The trace level can be changed at runtime by executing the SQL command <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for <code>System.out</code> tracing) or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing). Example:
@features_1539_h3
@features_1540_h3
Setting the Maximum Size of the Trace File
@features_1540_p
@features_1541_p
When using a high trace level, the trace file can get very big quickly. The default size limit is 16 MB, if the trace file exceeds this limit, it is renamed to <code>.old</code> and a new file is created. If another such file exists, it is deleted. To limit the size to a certain number of megabytes, use <code>SET TRACE_MAX_FILE_SIZE mb</code> . Example:
@features_1541_h3
@features_1542_h3
Java Code Generation
@features_1542_p
@features_1543_p
When setting the trace level to <code>INFO</code> or <code>DEBUG</code> , Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this:
@features_1543_p
@features_1544_p
To filter the Java source code, use the <code>ConvertTraceFile</code> tool as follows:
@features_1544_p
@features_1545_p
The generated file <code>Test.java</code> will contain the Java source code. The generated source code may be too large to compile (the size of a Java method is limited). If this is the case, the source code needs to be split in multiple methods. The password is not listed in the trace file and therefore not included in the source code.
@features_1545_h2
@features_1546_h2
Using Other Logging APIs
@features_1546_p
@features_1547_p
By default, this database uses its own native 'trace' facility. This facility is called 'trace' and not 'log' within this database to avoid confusion with the transaction log. Trace messages can be written to both file and <code>System.out</code> . In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
@features_1547_a
@features_1548_a
SLF4J
@features_1548_p
@features_1549_p
is a simple facade for various logging APIs and allows to plug in the desired implementation at deployment time. SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), Java logging, x4juli, and Simple Log.
@features_1549_p
@features_1550_p
To enable SLF4J, set the file trace level to 4 in the database URL:
@features_1550_p
@features_1551_p
Changing the log mechanism is not possible after the database is open, that means executing the SQL statement <code>SET TRACE_LEVEL_FILE 4</code> when the database is already open will not have the desired effect. To use SLF4J, all required jar files need to be in the classpath. If it does not work, check the file <code>&lt;database&gt;.trace.db</code> for error messages.
@features_1551_h2
@features_1552_h2
Read Only Databases
@features_1552_p
@features_1553_p
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 <code>SELECT</code> and <code>CALL</code> statements are allowed. To create a read-only database, close the database so that the log file gets smaller. Do not delete the log file. 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 whether database is read-only: by calling <code>Connection.isReadOnly()</code> or by executing the SQL statement <code>CALL READONLY()</code> .
@features_1553_h2
@features_1554_h2
Read Only Databases in Zip or Jar File
@features_1554_p
@features_1555_p
To create a read-only database in a zip file, first create a regular persistent database, and then create a backup. If you are using a database named <code>test</code> , an easy way to do that is using the <code>Backup</code> tool or the <code>BACKUP</code> SQL statement:
@features_1555_p
@features_1556_p
The database must not have pending changes, that means you need to close all connections to the database, open one single connection, and then execute the statement. Afterwards, you can log out, and directly open the database in the zip file using the following database URL:
@features_1556_p
@features_1557_p
Databases in zip files are read-only. The performance for some queries will be slower than when using a regular database, because random access in zip files is not supported (only streaming). How much this affects the performance depends on the queries and the data. The database is not read in memory; therefore large databases are supported as well. The same indexes are used as when using a regular database.
@features_1557_h2
@features_1558_h2
Graceful Handling of Low Disk Space Situations
@features_1558_p
@features_1559_p
If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement <code>SET DATABASE_EVENT_LISTENER</code> or use a database URL of the form <code>jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener'</code> (the quotes around the class name are required). See also the <code>DatabaseEventListener</code> API.
@features_1559_h3
@features_1560_h3
Opening a Corrupted Database
@features_1560_p
@features_1561_p
If a database cannot 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.
@features_1561_h2
@features_1562_h2
Computed Columns / Function Based Index
@features_1562_p
@features_1563_p
Function indexes are not directly supported by this database, but they can be emulated by using computed columns. For example, if an index on the upper-case version of a column is required, create a computed column with the upper-case version of the original column, and create an index for this column:
@features_1563_p
@features_1564_p
When inserting data, it is not required (and 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:
@features_1564_h2
@features_1565_h2
Multi-Dimensional Indexes
@features_1565_p
@features_1566_p
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.
@features_1566_p
@features_1567_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).
@features_1567_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.
@features_1568_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 <code>TestMultiDimension.java</code> .
@features_1568_h2
@features_1569_h2
Using Passwords
@features_1569_h3
@features_1570_h3
Using Secure Passwords
@features_1570_p
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:
@features_1571_p
i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
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:
@features_1572_h3
Passwords: Using Char Arrays instead of Strings
@features_1572_code
i'sE2rtPiUKtT
@features_1573_p
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).
from the sentence <code>it's easy to remember this password if you know the trick</code> .
@features_1574_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.
@features_1574_h3
Passwords: Using Char Arrays instead of Strings
@features_1575_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:
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).
@features_1576_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.
@features_1577_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:
@features_1578_p
This example requires Java 1.6. When using Swing, use <code>javax.swing.JPasswordField</code> .
@features_1577_h3
@features_1579_h3
Passing the User Name and/or Password in the URL
@features_1578_p
@features_1580_p
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.
@features_1579_h2
@features_1581_h2
User-Defined Functions and Stored Procedures
@features_1580_p
@features_1582_p
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:
@features_1581_p
@features_1583_p
The Java function must be registered in the database by calling <code>CREATE ALIAS</code> :
@features_1582_p
@features_1584_p
For a complete sample application, see <code>src/test/org/h2/samples/Function.java</code> .
@features_1583_h3
@features_1585_h3
Function Data Type Mapping
@features_1584_p
@features_1586_p
Functions that accept non-nullable parameters such as <code>int</code> will not be called if one of those parameters is <code>NULL</code> . Instead, the result of the function is <code>NULL</code> . If the function should be called if a parameter is <code>NULL</code> , you need to use <code>java.lang.Integer</code> instead.
@features_1585_p
@features_1587_p
SQL types are mapped to Java classes and vice-versa as in the JDBC API. For details, see <a href="datatypes.html">Data Types</a> . There are two special cases: <code>java.lang.Object</code> is mapped to <code>OTHER</code> (a serialized object). Therefore, <code>java.lang.Object</code> can not be used to match all SQL types (matching all SQL types is not supported). The second special case is <code>Object[]</code> : arrays of any class are mapped to <code>ARRAY</code> .
@features_1586_h3
@features_1588_h3
Functions that require a Connection
@features_1587_p
@features_1589_p
If the first parameter of a Java function is a <code>java.sql.Connection</code> , then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
@features_1588_h3
@features_1590_h3
Functions throwing an Exception
@features_1589_p
@features_1591_p
If a function throws an exception, then the current statement is rolled back and the exception is thrown to the application.
@features_1590_h3
@features_1592_h3
Functions returning a Result Set
@features_1591_p
@features_1593_p
Functions may returns a result set. Such a function can be called with the <code>CALL</code> statement:
@features_1592_h3
@features_1594_h3
Using SimpleResultSet
@features_1593_p
@features_1595_p
A function can create a result set using the <code>SimpleResultSet</code> tool:
@features_1594_h3
@features_1596_h3
Using a Function as a Table
@features_1595_p
@features_1597_p
A function that returns a result set can be used 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 <code>null</code> where not known at compile time). And then, while executing the statement to get the data (maybe multiple times 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 <code>jdbc:columnlist:connection</code> . Otherwise, the URL of the connection is <code>jdbc:default:connection</code> .
@features_1596_h2
@features_1598_h2
Triggers
@features_1597_p
@features_1599_p
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 <code>src/test/org/h2/samples/TriggerSample.java</code> . A Java trigger must implement the interface <code>org.h2.api.Trigger</code> . The trigger class must be available in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
@features_1598_p
@features_1600_p
The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database:
@features_1599_p
@features_1601_p
The trigger can be used to veto a change by throwing a <code>SQLException</code> .
@features_1600_h2
@features_1602_h2
Compacting a Database
@features_1601_p
@features_1603_p
Empty space in the database file is re-used automatically. To re-build the indexes, the simplest way is to delete the <code>.index.db</code> 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:
@features_1602_p
@features_1604_p
See also the sample application <code>org.h2.samples.Compact</code> . The commands <code>SCRIPT / RUNSCRIPT</code> can be used as well to create a backup of a database and re-build the database from the script.
@features_1603_h2
@features_1605_h2
Cache Settings
@features_1604_p
@features_1606_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 <code>CACHE_SIZE</code> . This setting can be set in the database connection URL ( <code>jdbc:h2:~/test;CACHE_SIZE=131072</code> ), or it can be changed at runtime using <code>SET CACHE_SIZE size</code> .
@features_1605_p
@features_1607_p
Also supported is a second level soft reference cache. Rows in this cache are only garbage collected on low memory. By default the second level cache is disabled. To enable it, use the prefix <code>SOFT_</code> . Example: <code>jdbc:h2:~/test;CACHE_TYPE=SOFT_LRU</code> .
@features_1606_p
@features_1608_p
To get information about page reads and writes, and the current caching algorithm in use, call <code>SELECT * FROM INFORMATION_SCHEMA.SETTINGS</code> . The number of pages read / written is listed for the data and index file.
@fragments_1000_b
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -297,7 +297,7 @@ java org.h2.test.TestAll timer
/*
documentation: rolling review at advanced.html (alphabetically)
documentation: rolling review at history.html
mvcc merge problem
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论