提交 20294dfb authored 作者: Thomas Mueller's avatar Thomas Mueller

Documentation: improved website translation

上级 a08877c0
...@@ -7,7 +7,7 @@ Initial Developer: H2 Group ...@@ -7,7 +7,7 @@ Initial Developer: H2 Group
--> -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title> <head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Advanced Topics Advanced
</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /> </title><link rel="stylesheet" type="text/css" href="stylesheet.css" />
<!-- [search] { --> <!-- [search] { -->
<script type="text/javascript" src="navigation.js"></script> <script type="text/javascript" src="navigation.js"></script>
...@@ -15,7 +15,7 @@ Advanced Topics ...@@ -15,7 +15,7 @@ Advanced Topics
<table class="content"><tr class="content"><td class="content"><div class="contentDiv"> <table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<!-- } --> <!-- } -->
<h1>Advanced Topics</h1> <h1>Advanced</h1>
<a href="#result_sets"> <a href="#result_sets">
Result Sets</a><br /> Result Sets</a><br />
<a href="#large_objects"> <a href="#large_objects">
...@@ -79,16 +79,16 @@ Before the result is returned to the application, all rows are read by the datab ...@@ -79,16 +79,16 @@ Before the result is returned to the application, all rows are read by the datab
Server side cursors are not supported currently. Server side cursors are not supported currently.
If only the first few rows are interesting for the application, then the If only the first few rows are interesting for the application, then the
result set size should be limited to improve the performance. result set size should be limited to improve the performance.
This can be done using <code class="notranslate">LIMIT</code> in a query This can be done using <code>LIMIT</code> in a query
(example: <code class="notranslate">SELECT * FROM TEST LIMIT 100</code>), (example: <code>SELECT * FROM TEST LIMIT 100</code>),
or by using Statement.setMaxRows(max). or by using <code>Statement.setMaxRows(max)</code>.
</p> </p>
<h3>Large Result Sets and External Sorting</h3> <h3>Large Result Sets and External Sorting</h3>
<p> <p>
For large result set, the result is buffered to disk. The threshold can be defined using the statement For large result set, the result is buffered to disk. The threshold can be defined using the statement
<code class="notranslate">SET MAX_MEMORY_ROWS</code>. <code>SET MAX_MEMORY_ROWS</code>.
If <code class="notranslate">ORDER BY</code> is used, the sorting is done using an If <code>ORDER BY</code> is used, the sorting is done using an
external sort algorithm. external sort algorithm.
In this case, each block of rows is sorted using quick sort, then written to disk; In this case, each block of rows is sorted using quick sort, then written to disk;
when reading the data, the blocks are merged together. when reading the data, the blocks are merged together.
...@@ -135,16 +135,16 @@ then compressing can save a lot of disk space (sometimes more than 50%), and rea ...@@ -135,16 +135,16 @@ then compressing can save a lot of disk space (sometimes more than 50%), and rea
<p> <p>
This database supports linked tables, which means tables that don't exist in the current database but This database supports linked tables, which means tables that don't exist in the current database but
are just links to another database. To create such a link, use the are just links to another database. To create such a link, use the
<code class="notranslate">CREATE LINKED TABLE</code> statement: <code>CREATE LINKED TABLE</code> statement:
</p> </p>
<pre class="notranslate"> <pre>
CREATE LINKED TABLE LINK('org.postgresql.Driver', 'jdbc:postgresql:test', 'sa', 'sa', 'TEST'); CREATE LINKED TABLE LINK('org.postgresql.Driver', 'jdbc:postgresql:test', 'sa', 'sa', 'TEST');
</pre> </pre>
<p> <p>
You can then access the table in the usual way. You can then access the table in the usual way.
Whenever the linked table is accessed, the database issues specific queries over JDBC. Whenever the linked table is accessed, the database issues specific queries over JDBC.
Using the example above, if you issue the query <code class="notranslate">SELECT * FROM LINK WHERE ID=1</code>, Using the example above, if you issue the query <code>SELECT * FROM LINK WHERE ID=1</code>,
then the following query is run against the PostgreSQL database: <code class="notranslate">SELECT * FROM TEST WHERE ID=?</code>. then the following query is run against the PostgreSQL database: <code>SELECT * FROM TEST WHERE ID=?</code>.
The same happens for insert and update statements. Only simple statements are executed against the The same happens for insert and update statements. Only simple statements are executed against the
target database, that means no joins. Prepared statements are used where possible. target database, that means no joins. Prepared statements are used where possible.
</p> </p>
...@@ -153,10 +153,10 @@ To view the statements that are executed against the target table, set the trace ...@@ -153,10 +153,10 @@ To view the statements that are executed against the target table, set the trace
</p> </p>
<p> <p>
If multiple linked tables point to the same database (using the same database URL), the connection 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 class="notranslate">h2.shareLinkedConnections=false</code>. is shared. To disable this, set the system property <code>h2.shareLinkedConnections=false</code>.
</p> </p>
<p> <p>
The <code class="notranslate">CREATE LINKED TABLE</code> statement supports an optional schema name parameter. The <code>CREATE LINKED TABLE</code> statement supports an optional schema name parameter.
See the grammar for details. See the grammar for details.
</p> </p>
...@@ -175,16 +175,16 @@ This database supports the following transaction isolation levels: ...@@ -175,16 +175,16 @@ This database supports the following transaction isolation levels:
This is the default level. This is the default level.
Read locks are released immediately. Read locks are released immediately.
Higher concurrency is possible when using this level.<br /> Higher concurrency is possible when using this level.<br />
To enable, execute the SQL statement <code class="notranslate">SET LOCK_MODE 3</code><br /> To enable, execute the SQL statement <code>SET LOCK_MODE 3</code><br />
or append <code class="notranslate">;LOCK_MODE=3</code> to the database URL: <code class="notranslate">jdbc:h2:~/test;LOCK_MODE=3</code> or append <code>;LOCK_MODE=3</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=3</code>
</li><li> </li><li>
<b>Serializable</b><br /> <b>Serializable</b><br />
To enable, execute the SQL statement <code class="notranslate">SET LOCK_MODE 1</code><br /> To enable, execute the SQL statement <code>SET LOCK_MODE 1</code><br />
or append <code class="notranslate">;LOCK_MODE=1</code> to the database URL: <code class="notranslate">jdbc:h2:~/test;LOCK_MODE=1</code> or append <code>;LOCK_MODE=1</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=1</code>
</li><li><b>Read Uncommitted</b><br /> </li><li><b>Read Uncommitted</b><br />
This level means that transaction isolation is disabled.<br /> This level means that transaction isolation is disabled.<br />
To enable, execute the SQL statement <code class="notranslate">SET LOCK_MODE 0</code><br /> To enable, execute the SQL statement <code>SET LOCK_MODE 0</code><br />
or append <code class="notranslate">;LOCK_MODE=0</code> to the database URL: <code class="notranslate">jdbc:h2:~/test;LOCK_MODE=0</code> or append <code>;LOCK_MODE=0</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=0</code>
</li> </li>
</ul> </ul>
<p> <p>
...@@ -238,7 +238,7 @@ for each connection. ...@@ -238,7 +238,7 @@ for each connection.
The MVCC feature allows higher concurrency than using (table level or row level) locks. The MVCC feature allows higher concurrency than using (table level or row level) locks.
When using MVCC in this database, delete, insert and update operations will only issue a When using MVCC in this database, delete, insert and update operations will only issue a
shared lock on the table. An exclusive lock is still used when adding or removing columns, shared lock on the table. An exclusive lock is still used when adding or removing columns,
when dropping the table, and when using <code class="notranslate">SELECT ... FOR UPDATE</code>. when dropping the table, and when using <code>SELECT ... FOR UPDATE</code>.
Connections only 'see' committed data, and own changes. That means, if connection A updates Connections only 'see' committed data, and own changes. That means, if connection A updates
a row but doesn't commit this change yet, connection B will see the old value. a row but doesn't commit this change yet, connection B will see the old value.
Only when the change is committed, the new value is visible by other connections Only when the change is committed, the new value is visible by other connections
...@@ -246,17 +246,17 @@ Only when the change is committed, the new value is visible by other connections ...@@ -246,17 +246,17 @@ Only when the change is committed, the new value is visible by other connections
database waits until it can apply the change, but at most until the lock timeout expires. database waits until it can apply the change, but at most until the lock timeout expires.
</p> </p>
<p> <p>
To use the MVCC feature, append <code class="notranslate">;MVCC=TRUE</code> to the database URL: To use the MVCC feature, append <code>;MVCC=TRUE</code> to the database URL:
</p> </p>
<pre class="notranslate"> <pre>
jdbc:h2:~/test;MVCC=TRUE jdbc:h2:~/test;MVCC=TRUE
</pre> </pre>
<p> <p>
The MVCC feature is not fully tested yet. The MVCC feature is not fully tested yet.
The limitations of the MVCC mode are: it can not be used at the same time as The limitations of the MVCC mode are: it can not be used at the same time as
<code class="notranslate">MULTI_THREADED=TRUE</code>; <code>MULTI_THREADED=TRUE</code>;
the complete undo log must fit in memory when using multi-version concurrency the complete undo log must fit in memory when using multi-version concurrency
(the setting <code class="notranslate">MAX_MEMORY_UNDO</code> has no effect). (the setting <code>MAX_MEMORY_UNDO</code> has no effect).
</p> </p>
<br /> <br />
...@@ -278,7 +278,7 @@ To initialize the cluster, use the following steps: ...@@ -278,7 +278,7 @@ To initialize the cluster, use the following steps:
</p> </p>
<ul> <ul>
<li>Create a database <li>Create a database
</li><li>Use the <code class="notranslate">CreateCluster</code> tool to copy the database to </li><li>Use the <code>CreateCluster</code> tool to copy the database to
another location and initialize the clustering. another location and initialize the clustering.
Afterwards, you have two databases containing the same data. Afterwards, you have two databases containing the same data.
</li><li>Start two servers (one for each copy of the database) </li><li>Start two servers (one for each copy of the database)
...@@ -292,11 +292,11 @@ In this example, the two databases reside on the same computer, but usually, the ...@@ -292,11 +292,11 @@ In this example, the two databases reside on the same computer, but usually, the
databases will be on different servers. databases will be on different servers.
</p> </p>
<ul> <ul>
<li>Create two directories: server1 and server2. <li>Create two directories: <code>server1, server2</code>.
Each directory will simulate a directory on a computer. Each directory will simulate a directory on a computer.
</li><li>Start a TCP server pointing to the first directory. </li><li>Start a TCP server pointing to the first directory.
You can do this using the command line: You can do this using the command line:
<pre class="notranslate"> <pre>
java org.h2.tools.Server java org.h2.tools.Server
-tcp -tcpPort 9101 -tcp -tcpPort 9101
-baseDir server1 -baseDir server1
...@@ -304,15 +304,15 @@ java org.h2.tools.Server ...@@ -304,15 +304,15 @@ java org.h2.tools.Server
</li><li>Start a second TCP server pointing to the second directory. </li><li>Start a second TCP server pointing to the second directory.
This will simulate a server running on a second (redundant) computer. This will simulate a server running on a second (redundant) computer.
You can do this using the command line: You can do this using the command line:
<pre class="notranslate"> <pre>
java org.h2.tools.Server java org.h2.tools.Server
-tcp -tcpPort 9102 -tcp -tcpPort 9102
-baseDir server2 -baseDir server2
</pre> </pre>
</li><li>Use the <code class="notranslate">CreateCluster</code> tool to initialize clustering. </li><li>Use the <code>CreateCluster</code> tool to initialize clustering.
This will automatically create a new, empty database if it does not exist. This will automatically create a new, empty database if it does not exist.
Run the tool on the command line: Run the tool on the command line:
<pre class="notranslate"> <pre>
java org.h2.tools.CreateCluster java org.h2.tools.CreateCluster
-urlSource jdbc:h2:tcp://localhost:9101/~/test -urlSource jdbc:h2:tcp://localhost:9101/~/test
-urlTarget jdbc:h2:tcp://localhost:9102/~/test -urlTarget jdbc:h2:tcp://localhost:9102/~/test
...@@ -321,13 +321,13 @@ java org.h2.tools.CreateCluster ...@@ -321,13 +321,13 @@ java org.h2.tools.CreateCluster
</pre> </pre>
</li><li>You can now connect to the databases using </li><li>You can now connect to the databases using
an application or the H2 Console using the JDBC URL an application or the H2 Console using the JDBC URL
<code class="notranslate">jdbc:h2:tcp://localhost:9101,localhost:9102/~/test</code> <code>jdbc:h2:tcp://localhost:9101,localhost:9102/~/test</code>
</li><li>If you stop a server (by killing the process), </li><li>If you stop a server (by killing the process),
you will notice that the other machine continues to work, you will notice that the other machine continues to work,
and therefore the database is still accessible. and therefore the database is still accessible.
</li><li>To restore the cluster, you first need to delete the </li><li>To restore the cluster, you first need to delete the
database that failed, then restart the server that was stopped, database that failed, then restart the server that was stopped,
and re-run the <code class="notranslate">CreateCluster</code> tool. and re-run the <code>CreateCluster</code> tool.
</li></ul> </li></ul>
<h3>Clustering Algorithm and Limitations</h3> <h3>Clustering Algorithm and Limitations</h3>
...@@ -335,10 +335,10 @@ and re-run the <code class="notranslate">CreateCluster</code> tool. ...@@ -335,10 +335,10 @@ and re-run the <code class="notranslate">CreateCluster</code> tool.
Read-only queries are only executed against the first cluster node, but all other statements are Read-only queries are only executed against the first cluster node, but all other statements are
executed against all nodes. There is currently no load balancing made to avoid problems with executed against all nodes. There is currently no load balancing made to avoid problems with
transactions. The following functions may yield different results on different cluster nodes and must be transactions. The following functions may yield different results on different cluster nodes and must be
executed with care: <code class="notranslate">RANDOM_UUID(), SECURE_RAND(), SESSION_ID(), executed with care: <code>RANDOM_UUID(), SECURE_RAND(), SESSION_ID(),
MEMORY_FREE(), MEMORY_USED(), CSVREAD(), CSVWRITE(), RAND()</code> [when not using a seed]. MEMORY_FREE(), MEMORY_USED(), CSVREAD(), CSVWRITE(), RAND()</code> [when not using a seed].
Those functions should not be used directly in modifying statements Those functions should not be used directly in modifying statements
(for example <code class="notranslate">INSERT, UPDATE, MERGE</code>). However, they can be used (for example <code>INSERT, UPDATE, MERGE</code>). However, they can be used
in read-only statements and the result can then be used for modifying statements. in read-only statements and the result can then be used for modifying statements.
</p> </p>
...@@ -351,15 +351,15 @@ The two phase commit protocol is supported. 2-phase-commit works as follows: ...@@ -351,15 +351,15 @@ The two phase commit protocol is supported. 2-phase-commit works as follows:
<li>Autocommit needs to be switched off <li>Autocommit needs to be switched off
</li><li>A transaction is started, for example by inserting a row </li><li>A transaction is started, for example by inserting a row
</li><li>The transaction is marked 'prepared' by executing the SQL statement </li><li>The transaction is marked 'prepared' by executing the SQL statement
<code class="notranslate">PREPARE COMMIT transactionName</code> <code>PREPARE COMMIT transactionName</code>
</li><li>The transaction can now be committed or rolled back </li><li>The transaction can now be committed or rolled back
</li><li>If a problem occurs before the transaction was successfully committed or rolled back </li><li>If a problem occurs before the transaction was successfully committed or rolled back
(for example because a network problem occurred), the transaction is in the state 'in-doubt' (for example because a network problem occurred), the transaction is in the state 'in-doubt'
</li><li>When re-connecting to the database, the in-doubt transactions can be listed </li><li>When re-connecting to the database, the in-doubt transactions can be listed
with <code class="notranslate">SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT</code> with <code>SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT</code>
</li><li>Each transaction in this list must now be committed or rolled back by executing </li><li>Each transaction in this list must now be committed or rolled back by executing
<code class="notranslate">COMMIT TRANSACTION transactionName</code> or <code>COMMIT TRANSACTION transactionName</code> or
<code class="notranslate">ROLLBACK TRANSACTION transactionName</code> <code>ROLLBACK TRANSACTION transactionName</code>
</li><li>The database needs to be closed and re-opened to apply the changes </li><li>The database needs to be closed and re-opened to apply the changes
</li></ul> </li></ul>
...@@ -382,14 +382,14 @@ Other database engines may commit the transaction in this case when the result s ...@@ -382,14 +382,14 @@ Other database engines may commit the transaction in this case when the result s
There is a list of keywords that can't be used as identifiers (table names, column names and so on), There is a list of keywords that can't be used as identifiers (table names, column names and so on),
unless they are quoted (surrounded with double quotes). The list is currently: unless they are quoted (surrounded with double quotes). The list is currently:
</p><p> </p><p>
<code class="notranslate"> <code>
CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DISTINCT, EXCEPT, EXISTS, FALSE, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DISTINCT, EXCEPT, EXISTS, FALSE,
FOR, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, IS, JOIN, LIKE, LIMIT, MINUS, NATURAL, NOT, NULL, FOR, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, IS, JOIN, LIKE, LIMIT, MINUS, NATURAL, NOT, NULL,
ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TRUE, UNION, WHERE ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TRUE, UNION, WHERE
</code> </code>
</p><p> </p><p>
Certain words of this list are keywords because they are functions that can be used without '()' for compatibility, Certain words of this list are keywords because they are functions that can be used without '()' for compatibility,
for example <code class="notranslate">CURRENT_TIMESTAMP</code>. for example <code>CURRENT_TIMESTAMP</code>.
</p> </p>
<br /> <br />
...@@ -409,39 +409,39 @@ There are various tools available to do that. The Java Service Wrapper from ...@@ -409,39 +409,39 @@ There are various tools available to do that. The Java Service Wrapper from
<a href="http://wrapper.tanukisoftware.org">Tanuki Software, Inc.</a> <a href="http://wrapper.tanukisoftware.org">Tanuki Software, Inc.</a>
is included in the installation. Batch files are provided to install, start, stop and uninstall the is included in the installation. Batch files are provided to install, start, stop and uninstall the
H2 Database Engine Service. This service contains the TCP Server and the H2 Console web application. H2 Database Engine Service. This service contains the TCP Server and the H2 Console web application.
The batch files are located in the directory <code class="notranslate">h2/service</code>. The batch files are located in the directory <code>h2/service</code>.
</p> </p>
<h3>Install the Service</h3> <h3>Install the Service</h3>
<p> <p>
The service needs to be registered as a Windows Service first. The service needs to be registered as a Windows Service first.
To do that, double click on <code class="notranslate">1_install_service.bat</code>. To do that, double click on <code>1_install_service.bat</code>.
If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear. If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear.
</p> </p>
<h3>Start the Service</h3> <h3>Start the Service</h3>
<p> <p>
You can start the H2 Database Engine Service using the service manager of Windows, You can start the H2 Database Engine Service using the service manager of Windows,
or by double clicking on <code class="notranslate">2_start_service.bat</code>. or by double clicking on <code>2_start_service.bat</code>.
Please note that the batch file does not print an error message if the service is not installed. Please note that the batch file does not print an error message if the service is not installed.
</p> </p>
<h3>Connect to the H2 Console</h3> <h3>Connect to the H2 Console</h3>
<p> <p>
After installing and starting the service, you can connect to the H2 Console application using a browser. After installing and starting the service, you can connect to the H2 Console application using a browser.
Double clicking on <code class="notranslate">3_start_browser.bat</code> to do that. The Double clicking on <code>3_start_browser.bat</code> to do that. The
default port (8082) is hard coded in the batch file. default port (8082) is hard coded in the batch file.
</p> </p>
<h3>Stop the Service</h3> <h3>Stop the Service</h3>
<p> <p>
To stop the service, double click on <code class="notranslate">4_stop_service.bat</code>. To stop the service, double click on <code>4_stop_service.bat</code>.
Please note that the batch file does not print an error message if the service is not installed or started. Please note that the batch file does not print an error message if the service is not installed or started.
</p> </p>
<h3>Uninstall the Service</h3> <h3>Uninstall the Service</h3>
<p> <p>
To uninstall the service, double click on <code class="notranslate">5_uninstall_service.bat</code>. To uninstall the service, double click on <code>5_uninstall_service.bat</code>.
If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear. If successful, a command prompt window will pop up and disappear immediately. If not, a message will appear.
</p> </p>
...@@ -456,7 +456,7 @@ as experimental. It should not be used for production applications. ...@@ -456,7 +456,7 @@ as experimental. It should not be used for production applications.
</p> </p>
<p> <p>
To use the PostgreSQL ODBC driver on 64 bit versions of Windows, To use the PostgreSQL ODBC driver on 64 bit versions of Windows,
first run <code class="notranslate">c:/windows/syswow64/odbcad32.exe</code>. first run <code>c:/windows/syswow64/odbcad32.exe</code>.
At this point you set up your DSN just like you would on any other system. At this point you set up your DSN just like you would on any other system.
See also: See also:
<a href="http://archives.postgresql.org/pgsql-odbc/2005-09/msg00125.php">Re: ODBC Driver on Windows 64 bit</a> <a href="http://archives.postgresql.org/pgsql-odbc/2005-09/msg00125.php">Re: ODBC Driver on Windows 64 bit</a>
...@@ -474,7 +474,7 @@ The Windows version of the PostgreSQL ODBC driver is available at ...@@ -474,7 +474,7 @@ The Windows version of the PostgreSQL ODBC driver is available at
<p> <p>
After installing the ODBC driver, start the H2 Server using the command line: After installing the ODBC driver, start the H2 Server using the command line:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Server java -cp h2*.jar org.h2.tools.Server
</pre> </pre>
<p> <p>
...@@ -482,13 +482,13 @@ The PG Server (PG for PostgreSQL protocol) is started as well. ...@@ -482,13 +482,13 @@ 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. 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 -baseDir to save databases in another directory, for example the user home directory:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Server -baseDir ~ java -cp h2*.jar org.h2.tools.Server -baseDir ~
</pre> </pre>
<p> <p>
The PG server can be started and stopped from within a Java application as follows: The PG server can be started and stopped from within a Java application as follows:
</p> </p>
<pre class="notranslate"> <pre>
Server server = Server.createPgServer("-baseDir", "~"); Server server = Server.createPgServer("-baseDir", "~");
server.start(); server.start();
... ...
...@@ -496,13 +496,13 @@ server.stop(); ...@@ -496,13 +496,13 @@ server.stop();
</pre> </pre>
<p> <p>
By default, only connections from localhost are allowed. To allow remote connections, use By default, only connections from localhost are allowed. To allow remote connections, use
<code class="notranslate">-pgAllowOthers</code> when starting the server. <code>-pgAllowOthers</code> when starting the server.
</p> </p>
<h3>ODBC Configuration</h3> <h3>ODBC Configuration</h3>
<p> <p>
After installing the driver, a new Data Source must be added. In Windows, After installing the driver, a new Data Source must be added. In Windows,
run <code class="notranslate">odbcad32.exe</code> to open the Data Source Administrator. Then click on 'Add...' run <code>odbcad32.exe</code> to open the Data Source Administrator. Then click on 'Add...'
and select the PostgreSQL Unicode driver. Then click 'Finish'. and select the PostgreSQL Unicode driver. Then click 'Finish'.
You will be able to change the connection properties: You will be able to change the connection properties:
</p> </p>
...@@ -571,18 +571,18 @@ An implementation of the ADO.NET interface is available in the open source proje ...@@ -571,18 +571,18 @@ An implementation of the ADO.NET interface is available in the open source proje
</li><li>Install <a href="http://www.ikvm.net">IKVM.NET</a>. </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 h2*.jar file to ikvm/bin
</li><li>Run the H2 Console using: </li><li>Run the H2 Console using:
<code class="notranslate">ikvm -jar h2*.jar</code> <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 .exe file using:
<code class="notranslate">ikvmc -target:winexe h2*.jar</code>. <code>ikvmc -target:winexe h2*.jar</code>.
You may ignore the warnings. You may ignore the warnings.
</li><li>Create a .dll file using (change the version accordingly): </li><li>Create a .dll file using (change the version accordingly):
<code class="notranslate">ikvmc.exe -target:library -version:1.0.69.0 h2*.jar</code> <code>ikvmc.exe -target:library -version:1.0.69.0 h2*.jar</code>
</li></ul> </li></ul>
<p> <p>
If you want your C# application use H2, you need to add the h2.dll and the 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: IKVM.OpenJDK.ClassLibrary.dll to your C# solution. Here some sample code:
</p> </p>
<pre class="notranslate"> <pre>
using System; using System;
using java.sql; using java.sql;
...@@ -649,7 +649,7 @@ Complete durability means all committed transaction survive a power failure. ...@@ -649,7 +649,7 @@ Complete durability means all committed transaction survive a power failure.
Some databases claim they can guarantee durability, but such claims are wrong. Some databases claim they can guarantee durability, but such claims are wrong.
A durability test was run against H2, HSQLDB, PostgreSQL, and Derby. A durability test was run against H2, HSQLDB, PostgreSQL, and Derby.
All of those databases sometimes lose committed transactions. All of those databases sometimes lose committed transactions.
The test is included in the H2 download, see org.h2.test.poweroff.Test. The test is included in the H2 download, see <code>org.h2.test.poweroff.Test</code>.
</p> </p>
<h3>Ways to (Not) Achieve Durability</h3> <h3>Ways to (Not) Achieve Durability</h3>
...@@ -657,15 +657,15 @@ The test is included in the H2 download, see org.h2.test.poweroff.Test. ...@@ -657,15 +657,15 @@ The test is included in the H2 download, see org.h2.test.poweroff.Test.
Making sure that committed transactions are not lost is more complicated than it seems first. 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 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 before the commit call returns. To do that, databases use different methods. One
is to use the 'synchronous write' file access mode. In Java, RandomAccessFile is to use the 'synchronous write' file access mode. In Java, <code>RandomAccessFile</code>
supports the modes <code class="notranslate">"rws"</code> and <code class="notranslate">"rwd"</code>: supports the modes <code>"rws"</code> and <code>"rwd"</code>:
</p> </p>
<ul> <ul>
<li><code class="notranslate">rwd</code>: every update to the file's content is written synchronously to the underlying storage device. <li><code>rwd</code>: every update to the file's content is written synchronously to the underlying storage device.
</li><li><code class="notranslate">rws</code>: in addition to rwd, every update to the metadata is written synchronously.</li> </li><li><code>rws</code>: in addition to <code>rwd</code>, every update to the metadata is written synchronously.</li>
</ul> </ul>
<p> <p>
A test (<code class="notranslate">org.h2.test.poweroff.TestWrite</code>) with one of those modes achieves A test (<code>org.h2.test.poweroff.TestWrite</code>) with one of those modes achieves
around 50 thousand write operations per second. 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. 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. This feature does not force changes to disk because it does not flush all buffers.
...@@ -678,18 +678,18 @@ or about 120 revolutions per second. There is an overhead, so the maximum write ...@@ -678,18 +678,18 @@ or about 120 revolutions per second. There is an overhead, so the maximum write
Calling fsync flushes the buffers. There are two ways to do that in Java: Calling fsync flushes the buffers. There are two ways to do that in Java:
</p> </p>
<ul> <ul>
<li><code class="notranslate">FileDescriptor.sync()</code>. The documentation says that this forces all system <li><code>FileDescriptor.sync()</code>. The documentation says that this forces all system
buffers to synchronize with the underlying device. buffers to synchronize with the underlying device.
Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor
have been written to the physical medium. have been written to the physical medium.
</li><li><code class="notranslate">FileChannel.force()</code> (since JDK 1.4). This method is supposed </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. to force any updates to this channel's file to be written to the storage device that contains it.
</li></ul> </li></ul>
<p> <p>
By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations 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. per second can be achieved, which is consistent with the RPM rate of the hard drive used.
Unfortunately, even when calling <code class="notranslate">FileDescriptor.sync()</code> or Unfortunately, even when calling <code>FileDescriptor.sync()</code> or
<code class="notranslate">FileChannel.force()</code>, <code>FileChannel.force()</code>,
data is not always persisted to the hard drive, because most hard drives do not obey data is not always persisted to the hard drive, because most hard drives do not obey
fsync(): see fsync(): see
<a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a>. <a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a>.
...@@ -706,8 +706,8 @@ Because of those reasons, the default behavior of H2 is to delay writing committ ...@@ -706,8 +706,8 @@ Because of those reasons, the default behavior of H2 is to delay writing committ
</p> </p>
<p> <p>
In H2, after a power failure, a bit more than one second of committed transactions may be lost. In H2, after a power failure, a bit more than one second of committed transactions may be lost.
To change the behavior, use <code class="notranslate">SET WRITE_DELAY</code> and To change the behavior, use <code>SET WRITE_DELAY</code> and
<code class="notranslate">CHECKPOINT SYNC</code>. <code>CHECKPOINT SYNC</code>.
Most other databases support commit delay as well. Most other databases support commit delay as well.
In the performance comparison, commit delay was used for all databases that support it. In the performance comparison, commit delay was used for all databases that support it.
</p> </p>
...@@ -715,7 +715,7 @@ In the performance comparison, commit delay was used for all databases that supp ...@@ -715,7 +715,7 @@ In the performance comparison, commit delay was used for all databases that supp
<h3>Running the Durability Test</h3> <h3>Running the Durability Test</h3>
<p> <p>
To test the durability / non-durability of this and other databases, you can use the test application To test the durability / non-durability of this and other databases, you can use the test application
in the package <code class="notranslate">org.h2.test.poweroff</code>. in the package <code>org.h2.test.poweroff</code>.
Two computers with network connection are required to run this test. Two computers with network connection are required to run this test.
One computer just listens, while the test application is run (and power is cut) on the other computer. One computer just listens, while the test application is run (and power is cut) on the other computer.
The computer with the listener application opens a TCP/IP port and listens for an incoming connection. The computer with the listener application opens a TCP/IP port and listens for an incoming connection.
...@@ -731,24 +731,24 @@ consult the source code of the listener and test application. ...@@ -731,24 +731,24 @@ consult the source code of the listener and test application.
<br /> <br />
<h2 id="using_recover_tool">Using the Recover Tool</h2> <h2 id="using_recover_tool">Using the Recover Tool</h2>
<p> <p>
The recover tool can be used to extract the contents of a data file, even if the database is corrupted. The <code>Recover</code> tool can be used to extract the contents of a data file, even if the database is corrupted.
It also extracts the content of the log file or large objects (CLOB or BLOB). It also extracts the content of the log file or large objects (CLOB or BLOB).
To run the tool, type on the command line: To run the tool, type on the command line:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Recover java -cp h2*.jar org.h2.tools.Recover
</pre> </pre>
<p> <p>
For each database in the current directory, a text file will be created. For each database in the current directory, a text file will be created.
This file contains raw insert statements (for the data) and data definition (DDL) statements to recreate This file contains raw insert statements (for the data) and data definition (DDL) statements to recreate
the schema of the database. This file can be executed using the RunScript tool or a the schema of the database. This file can be executed using the <code>RunScript</code> tool or a
<code class="notranslate">RUNSCRIPT FROM</code> SQL statement. The script includes at least one <code>RUNSCRIPT FROM</code> SQL statement. The script includes at least one
<code class="notranslate">CREATE USER</code> statement. If you run the script against a database that was created with the same <code>CREATE USER</code> statement. If you run the script against a database that was created with the same
user, or if there are conflicting users, running the script will fail. Consider running the script user, or if there are conflicting users, running the script will fail. Consider running the script
against a database that was created with a user name that is not in the script. against a database that was created with a user name that is not in the script.
</p> </p>
<p> <p>
The recover tool creates a SQL script from database files. It also processes the transaction log file(s), The <code>Recover</code> tool creates a SQL script from database files. It also processes the transaction log file(s),
however it does not automatically apply those changes. Usually, many of those changes are already however it does not automatically apply those changes. Usually, many of those changes are already
applied in the database. applied in the database.
</p> </p>
...@@ -776,7 +776,7 @@ The default method for database file locking is the 'File Method'. The algorithm ...@@ -776,7 +776,7 @@ The default method for database file locking is the 'File Method'. The algorithm
</p> </p>
<ul> <ul>
<li>If the lock file does not exist, it is created (using the atomic operation <li>If the lock file does not exist, it is created (using the atomic operation
<code class="notranslate">File.createNewFile</code>). <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 (20ms) and checks the file again. If the file was changed
during this time, the operation is aborted. This protects against a race condition 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 when one process deletes the lock file just after another one create it, and a third process creates
...@@ -813,7 +813,7 @@ to the user if it cannot open a database, and not try again in a (fast) loop. ...@@ -813,7 +813,7 @@ to the user if it cannot open a database, and not try again in a (fast) loop.
<h3>File Locking Method 'Socket'</h3> <h3>File Locking Method 'Socket'</h3>
<p> <p>
There is a second locking mechanism implemented, but disabled by default. There is a second locking mechanism implemented, but disabled by default.
To use it, append <code class="notranslate">;FILE_LOCK=SOCKET</code> to the database URL. To use it, append <code>;FILE_LOCK=SOCKET</code> to the database URL.
The algorithm is: The algorithm is:
</p> </p>
<ul> <ul>
...@@ -844,17 +844,17 @@ This database engine provides a solution for the security vulnerability known as ...@@ -844,17 +844,17 @@ This database engine provides a solution for the security vulnerability known as
Here is a short description of what SQL injection means. Here is a short description of what SQL injection means.
Some applications build SQL statements with embedded user input such as: Some applications build SQL statements with embedded user input such as:
</p> </p>
<pre class="notranslate"> <pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD='"+pwd+"'"; String sql = "SELECT * FROM USERS WHERE PASSWORD='"+pwd+"'";
ResultSet rs = conn.createStatement().executeQuery(sql); ResultSet rs = conn.createStatement().executeQuery(sql);
</pre> </pre>
<p> <p>
If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded, 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 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 class="notranslate">' OR ''='</code>. such as (in this example) this password: <code>' OR ''='</code>.
In this case the statement becomes: In this case the statement becomes:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM USERS WHERE PASSWORD='' OR ''=''; SELECT * FROM USERS WHERE PASSWORD='' OR ''='';
</pre> </pre>
<p> <p>
...@@ -867,7 +867,7 @@ For more information about SQL Injection, see Glossary and Links. ...@@ -867,7 +867,7 @@ For more information about SQL Injection, see Glossary and Links.
SQL Injection is not possible if user input is not directly embedded in SQL statements. SQL Injection is not possible if user input is not directly embedded in SQL statements.
A simple solution for the problem above is to use a prepared statement: A simple solution for the problem above is to use a prepared statement:
</p> </p>
<pre class="notranslate"> <pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD=?"; String sql = "SELECT * FROM USERS WHERE PASSWORD=?";
PreparedStatement prep = conn.prepareStatement(sql); PreparedStatement prep = conn.prepareStatement(sql);
prep.setString(1, pwd); prep.setString(1, pwd);
...@@ -878,31 +878,31 @@ This database provides a way to enforce usage of parameters when passing user in ...@@ -878,31 +878,31 @@ This database provides a way to enforce usage of parameters when passing user in
to the database. This is done by disabling embedded literals in SQL statements. to the database. This is done by disabling embedded literals in SQL statements.
To do this, execute the statement: To do this, execute the statement:
</p> </p>
<pre class="notranslate"> <pre>
SET ALLOW_LITERALS NONE; SET ALLOW_LITERALS NONE;
</pre> </pre>
<p> <p>
Afterwards, SQL statements with text and number literals are not allowed any more. Afterwards, SQL statements with text and number literals are not allowed any more.
That means, SQL statement of the form <code class="notranslate">WHERE NAME='abc'</code> That means, SQL statement of the form <code>WHERE NAME='abc'</code>
or <code class="notranslate">WHERE CustomerId=10</code> will fail. or <code>WHERE CustomerId=10</code> will fail.
It is still possible to use prepared statements and parameters as described above. Also, it is still possible to generate It is still possible to use prepared statements and parameters as described above. Also, it is still possible to generate
SQL statements dynamically, and use the Statement API, as long as the SQL statements SQL statements dynamically, and use the Statement API, as long as the SQL statements
do not include literals. do not include literals.
There is also a second mode where number literals are allowed: There is also a second mode where number literals are allowed:
<code class="notranslate">SET ALLOW_LITERALS NUMBERS</code>. <code>SET ALLOW_LITERALS NUMBERS</code>.
To allow all literals, execute <code class="notranslate">SET ALLOW_LITERALS ALL</code> To allow all literals, execute <code>SET ALLOW_LITERALS ALL</code>
(this is the default setting). Literals can only be enabled or disabled by an administrator. (this is the default setting). Literals can only be enabled or disabled by an administrator.
</p> </p>
<h3>Using Constants</h3> <h3>Using Constants</h3>
<p> <p>
Disabling literals also means disabling hard-coded 'constant' literals. This database supports Disabling literals also means disabling hard-coded 'constant' literals. This database supports
defining constants using the <code class="notranslate">CREATE CONSTANT</code> command. defining constants using the <code>CREATE CONSTANT</code> command.
Constants can be defined only Constants can be defined only
when literals are enabled, but used even when literals are disabled. To avoid name clashes when literals are enabled, but used even when literals are disabled. To avoid name clashes
with column names, constants can be defined in other schemas: with column names, constants can be defined in other schemas:
</p> </p>
<pre class="notranslate"> <pre>
CREATE SCHEMA CONST AUTHORIZATION SA; CREATE SCHEMA CONST AUTHORIZATION SA;
CREATE CONSTANT CONST.ACTIVE VALUE 'Active'; CREATE CONSTANT CONST.ACTIVE VALUE 'Active';
CREATE CONSTANT CONST.INACTIVE VALUE 'Inactive'; CREATE CONSTANT CONST.INACTIVE VALUE 'Inactive';
...@@ -916,9 +916,9 @@ time, the source code is easier to understand and change. ...@@ -916,9 +916,9 @@ time, the source code is easier to understand and change.
<h3>Using the ZERO() Function</h3> <h3>Using the ZERO() Function</h3>
<p> <p>
It is not required to create a constant for the number 0 as there is already a built-in function <code class="notranslate">ZERO()</code>: It is not required to create a constant for the number 0 as there is already a built-in function <code>ZERO()</code>:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO(); SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO();
</pre> </pre>
...@@ -927,9 +927,9 @@ SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO(); ...@@ -927,9 +927,9 @@ SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO();
<p> <p>
By default this database does not allow others to connect when starting the H2 Console, By default this database does not allow others to connect when starting the H2 Console,
the TCP server, or the PG server. Remote access can be enabled using the command line the TCP server, or the PG server. Remote access can be enabled using the command line
options <code class="notranslate">-webAllowOthers, -tcpAllowOthers, -pgAllowOthers</code>. options <code>-webAllowOthers, -tcpAllowOthers, -pgAllowOthers</code>.
If you enable remote access, please also consider using the options If you enable remote access, please also consider using the options
<code class="notranslate">-baseDir, -ifExists</code>, so that remote <code>-baseDir, -ifExists</code>, so that remote
users can not create new databases or access existing databases with weak passwords. Also, users can not create new databases or access existing databases with weak passwords. Also,
ensure the existing accessible databases are protected using a strong password. ensure the existing accessible databases are protected using a strong password.
</p> </p>
...@@ -939,9 +939,9 @@ ensure the existing accessible databases are protected using a strong password. ...@@ -939,9 +939,9 @@ ensure the existing accessible databases are protected using a strong password.
<p> <p>
By default there is no restriction on loading classes and executing Java code for admins. 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 That means an admin may call system functions such as
<code class="notranslate">System.setProperty</code> by executing: <code>System.setProperty</code> by executing:
</p> </p>
<pre class="notranslate"> <pre>
CREATE ALIAS SET_PROPERTY FOR "java.lang.System.setProperty"; CREATE ALIAS SET_PROPERTY FOR "java.lang.System.setProperty";
CALL SET_PROPERTY('abc', '1'); CALL SET_PROPERTY('abc', '1');
CREATE ALIAS GET_PROPERTY FOR "java.lang.System.getProperty"; CREATE ALIAS GET_PROPERTY FOR "java.lang.System.getProperty";
...@@ -950,11 +950,11 @@ CALL GET_PROPERTY('abc'); ...@@ -950,11 +950,11 @@ CALL GET_PROPERTY('abc');
<p> <p>
To restrict users (including admins) from loading classes and executing code, To restrict users (including admins) from loading classes and executing code,
the list of allowed classes can be set in the system property the list of allowed classes can be set in the system property
<code class="notranslate">h2.allowedClasses</code> <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 '*').
By default all classes are allowed. Example: By default all classes are allowed. Example:
</p> </p>
<pre class="notranslate"> <pre>
java -Dh2.allowedClasses=java.lang.Math,com.acme.* java -Dh2.allowedClasses=java.lang.Math,com.acme.*
</pre> </pre>
<p> <p>
...@@ -1052,8 +1052,8 @@ database operations take about 2.2 times longer when using XTEA, and 2.5 times l ...@@ -1052,8 +1052,8 @@ database operations take about 2.2 times longer when using XTEA, and 2.5 times l
<h3>Wrong Password / User Name Delay</h3> <h3>Wrong Password / User Name Delay</h3>
<p> <p>
To protect against remote brute force password attacks, the delay after each unsuccessful To protect against remote brute force password attacks, the delay after each unsuccessful
login gets double as long. Use the system properties <code class="notranslate">h2.delayWrongPasswordMin</code> login gets double as long. Use the system properties <code>h2.delayWrongPasswordMin</code>
and <code class="notranslate">h2.delayWrongPasswordMax</code> to change the minimum (the default is 250 milliseconds) and <code>h2.delayWrongPasswordMax</code> to change the minimum (the default is 250 milliseconds)
or maximum delay (the default is 4000 milliseconds, or 4 seconds). The delay only or maximum delay (the default is 4000 milliseconds, or 4 seconds). The delay only
applies for those using the wrong password. Normally there is no delay for a user that knows the correct applies for those using the wrong password. Normally there is no delay for a user that knows the correct
password, with one exception: after using the wrong password, there is a delay of up to (randomly distributed) password, with one exception: after using the wrong password, there is a delay of up to (randomly distributed)
...@@ -1069,7 +1069,7 @@ if the user name was wrong or the password. ...@@ -1069,7 +1069,7 @@ if the user name was wrong or the password.
<h3>HTTPS Connections</h3> <h3>HTTPS Connections</h3>
<p> <p>
The web server supports HTTP and HTTPS connections using <code class="notranslate">SSLServerSocket</code>. The web server supports HTTP and HTTPS connections using <code>SSLServerSocket</code>.
There is a default self-certified certificate to support an easy starting point, but There is a default self-certified certificate to support an easy starting point, but
custom certificates are supported as well. custom certificates are supported as well.
</p> </p>
...@@ -1078,18 +1078,18 @@ custom certificates are supported as well. ...@@ -1078,18 +1078,18 @@ custom certificates are supported as well.
<h2 id="ssl_tls_connections">SSL/TLS Connections</h2> <h2 id="ssl_tls_connections">SSL/TLS Connections</h2>
<p> <p>
Remote SSL/TLS connections are supported using the Java Secure Socket Extension Remote SSL/TLS connections are supported using the Java Secure Socket Extension
(<code class="notranslate">SSLServerSocket, SSLSocket</code>). By default, anonymous SSL is enabled. (<code>SSLServerSocket, SSLSocket</code>). By default, anonymous SSL is enabled.
The default cipher suite is <code class="notranslate">SSL_DH_anon_WITH_RC4_128_MD5</code>. The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code>.
</p> </p>
<p> <p>
To use your own keystore, set the system properties <code class="notranslate">javax.net.ssl.keyStore</code> and To use your own keystore, set the system properties <code>javax.net.ssl.keyStore</code> and
<code class="notranslate">javax.net.ssl.keyStorePassword</code> before starting the H2 server and client. <code>javax.net.ssl.keyStorePassword</code> before starting the H2 server and client.
See also <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores"> See also <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores">
Customizing the Default Key and Trust Stores, Store Types, and Store Passwords</a> Customizing the Default Key and Trust Stores, Store Types, and Store Passwords</a>
for more information. for more information.
</p> </p>
<p> <p>
To disable anonymous SSL, set the system property <code class="notranslate">h2.enableAnonymousSSL</code> to false. To disable anonymous SSL, set the system property <code>h2.enableAnonymousSSL</code> to false.
</p> </p>
<br /> <br />
...@@ -1102,11 +1102,11 @@ using the probability theory. See also 'Birthday Paradox'. ...@@ -1102,11 +1102,11 @@ using the probability theory. See also 'Birthday Paradox'.
Standardized randomly generated UUIDs have 122 random bits. Standardized randomly generated UUIDs have 122 random bits.
4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz). 4 bits are used for the version (Randomly generated UUID), and 2 bits for the variant (Leach-Salz).
This database supports generating such UUIDs using the built-in function This database supports generating such UUIDs using the built-in function
<code class="notranslate">RANDOM_UUID()</code>. <code>RANDOM_UUID()</code>.
Here is a small program to estimate the probability of having two identical UUIDs Here is a small program to estimate the probability of having two identical UUIDs
after generating a number of values: after generating a number of values:
</p> </p>
<pre class="notranslate"> <pre>
public class Test { public class Test {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
double x = Math.pow(2, 122); double x = Math.pow(2, 122);
...@@ -1123,11 +1123,12 @@ public class Test { ...@@ -1123,11 +1123,12 @@ public class Test {
<p> <p>
Some values are: Some values are:
</p> </p>
<pre> <table>
2^36=68'719'476'736 probability: 0.000'000'000'000'000'4 <tr><th>Number of UUIs</th><th>Probability of Duplicates</th></tr>
2^41=2'199'023'255'552 probability: 0.000'000'000'000'4 <tr><td>2^36=68'719'476'736</td><td>0.000'000'000'000'000'4</td></tr>
2^46=70'368'744'177'664 probability: 0.000'000'000'4 <tr><td>2^41=2'199'023'255'552</td><td>0.000'000'000'000'4</td></tr>
</pre> <tr><td>2^46=70'368'744'177'664</td><td>0.000'000'000'4</td></tr>
</table>
<p> <p>
To help non-mathematicians understand what those numbers mean, here a comparison: To help non-mathematicians understand what those numbers mean, here a comparison:
one's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion, one's annual risk of being hit by a meteorite is estimated to be one chance in 17 billion,
...@@ -1138,16 +1139,16 @@ that means the probability is about 0.000'000'000'06. ...@@ -1138,16 +1139,16 @@ that means the probability is about 0.000'000'000'06.
<h2 id="system_properties">Settings Read from System Properties</h2> <h2 id="system_properties">Settings Read from System Properties</h2>
<p> <p>
Some settings of the database can be set on the command line using Some settings of the database can be set on the command line using
<code class="notranslate">-DpropertyName=value</code>. It is usually not required to change those settings manually. <code>-DpropertyName=value</code>. It is usually not required to change those settings manually.
The settings are case sensitive. The settings are case sensitive.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
java -Dh2.serverCachedObjects=256 org.h2.tools.Server java -Dh2.serverCachedObjects=256 org.h2.tools.Server
</pre> </pre>
<p> <p>
The current value of the settings can be read in the table The current value of the settings can be read in the table
<code class="notranslate">INFORMATION_SCHEMA.SETTINGS</code>. <code>INFORMATION_SCHEMA.SETTINGS</code>.
</p> </p>
<p> <p>
For a complete list of settings, see For a complete list of settings, see
...@@ -1159,7 +1160,7 @@ For a complete list of settings, see ...@@ -1159,7 +1160,7 @@ For a complete list of settings, see
<p> <p>
Usually server sockets accept connections on any/all local addresses. Usually server sockets accept connections on any/all local addresses.
This may be a problem on multi-homed hosts. This may be a problem on multi-homed hosts.
To bind only to one address, use the system property <code class="notranslate">h2.bindAddress</code>. To bind only to one address, use the system property <code>h2.bindAddress</code>.
This setting is used for both regular server sockets and for SSL server sockets. This setting is used for both regular server sockets and for SSL server sockets.
IPv4 and IPv6 address formats are supported. IPv4 and IPv6 address formats are supported.
</p> </p>
...@@ -1170,20 +1171,20 @@ IPv4 and IPv6 address formats are supported. ...@@ -1170,20 +1171,20 @@ IPv4 and IPv6 address formats are supported.
This database supports a pluggable file system API. The file system implementation This database supports a pluggable file system API. The file system implementation
is selected using a file name prefix. The following file systems are included: is selected using a file name prefix. The following file systems are included:
</p> </p>
<ul><li><code class="notranslate">zip:</code> read-only zip-file based file system. Format: <code class="notranslate">zip:/zipFileName!/fileName</code>. <ul><li><code>zip:</code> read-only zip-file based file system. Format: <code>zip:/zipFileName!/fileName</code>.
</li><li><code class="notranslate">nio:</code> file system that uses <code class="notranslate">FileChannel</code> instead of <code class="notranslate">RandomAccessFile</code> (faster in some operating systems). </li><li><code>nio:</code> file system that uses <code>FileChannel</code> instead of <code>RandomAccessFile</code> (faster in some operating systems).
</li><li><code class="notranslate">nioMapped:</code> file system that uses memory mapped files (faster in some operating systems). </li><li><code>nioMapped:</code> file system that uses memory mapped files (faster in some operating systems).
</li><li><code class="notranslate">split:</code> file system that splits files in 1 GB files (stackable with other file systems). </li><li><code>split:</code> file system that splits files in 1 GB files (stackable with other file systems).
</li><li><code class="notranslate">memFS:</code> in-memory file system (experimental; used for testing). </li><li><code>memFS:</code> in-memory file system (experimental; used for testing).
</li><li><code class="notranslate">memLZF:</code> compressing in-memory file system (experimental; used for testing). </li><li><code>memLZF:</code> compressing in-memory file system (experimental; used for testing).
</li></ul> </li></ul>
<p> <p>
As an example, to use the the <code class="notranslate">nio</code> file system, use the following database URL: As an example, to use the the <code>nio</code> file system, use the following database URL:
<code class="notranslate">jdbc:h2:nio:~/test</code>. <code>jdbc:h2:nio:~/test</code>.
</p> </p>
<p> <p>
To register a new file system, extend the classes <code class="notranslate">org.h2.store.fs.FileSystem, FileObject</code>, To register a new file system, extend the classes <code>org.h2.store.fs.FileSystem, FileObject</code>,
and call the method <code class="notranslate">FileSystem.register</code> before using it. and call the method <code>FileSystem.register</code> before using it.
</p> </p>
<br /> <br />
...@@ -1198,16 +1199,16 @@ This database has the following known limitations: ...@@ -1198,16 +1199,16 @@ This database has the following known limitations:
</li><li>BLOB and CLOB size limit: every CLOB or BLOB can be up to 256 GB. </li><li>BLOB and CLOB size limit: every CLOB or BLOB can be up to 256 GB.
</li><li>The maximum file size for FAT or FAT32 file systems is 4 GB. That means when using FAT or FAT32, </li><li>The maximum file size for FAT or FAT32 file systems is 4 GB. That means when using FAT or FAT32,
the limit is 4 GB for the data. This is the limitation of the file system. The database does provide a the limit is 4 GB for the data. This is the limitation of the file system. The database does provide a
workaround for this problem, it is to use the file name prefix 'split:'. In that case files are split into workaround for this problem, it is to use the file name prefix <code>split:</code>. In that case files are split into
files of 1 GB by default. An example database URL is: files of 1 GB by default. An example database URL is:
<code class="notranslate">jdbc:h2:split:~/test</code>. <code>jdbc:h2:split:~/test</code>.
</li><li>The maximum number of rows per table is 2'147'483'648. </li><li>The maximum number of rows per table is 2'147'483'648.
</li><li>Main memory requirements: The larger the database, the more main memory is required. </li><li>Main memory requirements: The larger the database, the more main memory is required.
With the default storage mechanism, the minimum main memory required for a 12 GB database is around 240 MB. With the default storage mechanism, the minimum main memory required for a 12 GB database is around 240 MB.
With the page store (experimental), the minimum main memory required is much lower, around 1 MB for each 8 GB database file size. With the page store (experimental), the minimum main memory required is much lower, around 1 MB for each 8 GB database file size.
</li><li>Limit on the complexity of SQL statements. </li><li>Limit on the complexity of SQL statements.
Statements of the following form will result in a stack overflow exception: Statements of the following form will result in a stack overflow exception:
<pre class="notranslate"> <pre>
SELECT * FROM DUAL WHERE X = 1 SELECT * FROM DUAL WHERE X = 1
OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2
-- repeat previous line 500 times -- -- repeat previous line 500 times --
......
...@@ -67,20 +67,20 @@ Newer version or compatible software works too. ...@@ -67,20 +67,20 @@ Newer version or compatible software works too.
<h2 id="building">Building the Software</h2> <h2 id="building">Building the Software</h2>
<p> <p>
You need to install a JDK, for example the Sun JDK version 1.5 or 1.6. You need to install a JDK, for example the Sun JDK version 1.5 or 1.6.
Ensure that Java binary directory is included in the <code class="notranslate">PATH</code> environment variable, and that Ensure that Java binary directory is included in the <code>PATH</code> environment variable, and that
the environment variable <code class="notranslate">JAVA_HOME</code> points to your Java installation. the environment variable <code>JAVA_HOME</code> points to your Java installation.
On the command line, go to the directory <code class="notranslate">h2</code> and execute the following command: On the command line, go to the directory <code>h2</code> and execute the following command:
</p> </p>
<pre class="notranslate"> <pre>
build -? build -?
</pre> </pre>
<p> <p>
For Linux and OS X, use <code class="notranslate">./build.sh</code> instead of <code class="notranslate">build</code>. For Linux and OS X, use <code>./build.sh</code> instead of <code>build</code>.
</p> </p>
<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 jar file, execute (Windows):
</p> </p>
<pre class="notranslate"> <pre>
build jar build jar
</pre> </pre>
...@@ -89,7 +89,7 @@ build jar ...@@ -89,7 +89,7 @@ build jar
By default the source code uses Java 1.5 features, however Java 1.6 is supported as well. 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 install version of Java, run:
</p> </p>
<pre class="notranslate"> <pre>
build switchSource build switchSource
</pre> </pre>
...@@ -98,20 +98,20 @@ build switchSource ...@@ -98,20 +98,20 @@ build switchSource
<p> <p>
The build system can generate smaller jar files as well. The following targets are currently supported: The build system can generate smaller jar files as well. The following targets are currently supported:
</p> </p>
<ul><li><code class="notranslate">jarClient</code> <ul><li><code>jarClient</code>
creates the file <code class="notranslate">h2client.jar</code>. This only contains the JDBC client. creates the file <code>h2client.jar</code>. This only contains the JDBC client.
</li><li><code class="notranslate">jarSmall</code> </li><li><code>jarSmall</code>
creates the file <code class="notranslate">h2small.jar</code>. creates the file <code>h2small.jar</code>.
This only contains the embedded database. Debug information is disabled. This only contains the embedded database. Debug information is disabled.
</li><li><code class="notranslate">jarJaqu</code> </li><li><code>jarJaqu</code>
creates the file <code class="notranslate">h2jaqu.jar</code>. creates the file <code>h2jaqu.jar</code>.
This only contains the JaQu (Java Query) implementation. All other jar files do not include JaQu. This only contains the JaQu (Java Query) implementation. All other jar files do not include JaQu.
</li><li><code class="notranslate">javadocImpl</code> creates the Javadocs of the implementation. </li><li><code>javadocImpl</code> creates the Javadocs of the implementation.
</li></ul> </li></ul>
<p> <p>
To create the file <code class="notranslate">h2client.jar</code>, go to the directory h2 and execute the following command: To create the file <code>h2client.jar</code>, go to the directory <code>h2</code> and execute the following command:
</p> </p>
<pre class="notranslate"> <pre>
build jarClient build jarClient
</pre> </pre>
...@@ -122,7 +122,7 @@ build jarClient ...@@ -122,7 +122,7 @@ build jarClient
You can include the database in your Maven 2 project as a dependency. You can include the database in your Maven 2 project as a dependency.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
&lt;dependency&gt; &lt;dependency&gt;
&lt;groupId&gt;com.h2database&lt;/groupId&gt; &lt;groupId&gt;com.h2database&lt;/groupId&gt;
&lt;artifactId&gt;h2&lt;/artifactId&gt; &lt;artifactId&gt;h2&lt;/artifactId&gt;
...@@ -139,13 +139,13 @@ they are available there. ...@@ -139,13 +139,13 @@ they are available there.
<p> <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 'snapshot' H2 jar file and upload it the to the local Maven 2 repository, execute the following command:
</p> </p>
<pre class="notranslate"> <pre>
build mavenInstallLocal build mavenInstallLocal
</pre> </pre>
<p> <p>
Afterwards, you can include the database in your Maven 2 project as a dependency: Afterwards, you can include the database in your Maven 2 project as a dependency:
</p> </p>
<pre class="notranslate"> <pre>
&lt;dependency&gt; &lt;dependency&gt;
&lt;groupId&gt;com.h2database&lt;/groupId&gt; &lt;groupId&gt;com.h2database&lt;/groupId&gt;
&lt;artifactId&gt;h2&lt;/artifactId&gt; &lt;artifactId&gt;h2&lt;/artifactId&gt;
...@@ -159,17 +159,17 @@ Afterwards, you can include the database in your Maven 2 project as a dependency ...@@ -159,17 +159,17 @@ Afterwards, you can include the database in your Maven 2 project as a dependency
The translation of this software is split into the following parts: The translation of this software is split into the following parts:
</p> </p>
<ul> <ul>
<li>H2 Console: <code class="notranslate">src/main/org/h2/server/web/res/_text_*.properties</code> <li>H2 Console: <code>src/main/org/h2/server/web/res/_text_*.properties</code>
</li><li>Error messages: <code class="notranslate">src/main/org/h2/res/_messages_*.properties</code> </li><li>Error messages: <code>src/main/org/h2/res/_messages_*.properties</code>
</li><li>Web site: <code class="notranslate">src/docsrc/text/_docs_*.utf8.txt</code> </li><li>Web site: <code>src/docsrc/text/_docs_*.utf8.txt</code>
</li></ul> </li></ul>
<p> <p>
To translate the H2 Console, start it and select Preferences / Translate. To translate the H2 Console, start it and select Preferences / Translate.
The conversion between UTF-8 and Java encoding (using the <code class="notranslate">\u</code> syntax), The conversion between UTF-8 and Java encoding (using the <code>\u</code> syntax),
as well as the HTML entities (<code class="notranslate">&amp;#..;</code>) as well as the HTML entities (<code>&amp;#..;</code>)
is automated by running the tool <code class="notranslate">PropertiesToUTF8</code>. is automated by running the tool <code>PropertiesToUTF8</code>.
The web site translation is automated as well, The web site translation is automated as well,
using <code class="notranslate">build docs</code>. using <code>build docs</code>.
</p> </p>
<br /> <br />
...@@ -180,25 +180,25 @@ If you like to provide patches, please consider the following guidelines to simp ...@@ -180,25 +180,25 @@ If you like to provide patches, please consider the following guidelines to simp
<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 Environment).
</li><li>Follow the coding style used in the project, and use Checkstyle (see above) to verify. </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). For example, do not use tabs (use spaces instead).
The checkstyle configuration is in <code class="notranslate">src/installer/checkstyle.xml</code>. The checkstyle configuration is in <code>src/installer/checkstyle.xml</code>.
</li><li>Please provide test cases and integrate them into the test suite. </li><li>Please provide test cases and integrate them into the test suite.
For Java level tests, see <code class="notranslate">src/test/org/h2/test/TestAll.java</code>. For Java level tests, see <code>src/test/org/h2/test/TestAll.java</code>.
For SQL level tests, see <code class="notranslate">src/test/org/h2/test/test.in.txt</code> or For SQL level tests, see <code>src/test/org/h2/test/test.in.txt</code> or
<code class="notranslate">testSimple.in.txt</code>. <code>testSimple.in.txt</code>.
</li><li>The test cases should cover at least 90% of the changed and new code; </li><li>The test cases should cover at least 90% of the changed and new code;
use a code coverage tool to verify that (see above). use a code coverage tool to verify that (see above).
or use the build target <code class="notranslate">coverage</code>. or use the build target <code>coverage</code>.
</li><li>Verify that you did not break other features: run the test cases by executing </li><li>Verify that you did not break other features: run the test cases by executing
<code class="notranslate">build test</code>. <code>build test</code>.
</li><li>Provide end user documentation if required (<code class="notranslate">src/docsrc/html/*</code>). </li><li>Provide end user documentation if required (<code>src/docsrc/html/*</code>).
</li><li>Document grammar changes in <code class="notranslate">src/main/org/h2/res/help.csv</code> </li><li>Document grammar changes in <code>src/main/org/h2/res/help.csv</code>
</li><li>Provide a change log entry (<code class="notranslate">src/docsrc/html/changelog.html</code>). </li><li>Provide a change log entry (<code>src/docsrc/html/changelog.html</code>).
</li><li>Verify the spelling using <code class="notranslate">build spellcheck</code>. If required </li><li>Verify the spelling using <code>build spellcheck</code>. If required
add the new words to <code class="notranslate">src/tools/org/h2/build/doc/dictionary.txt</code>. add the new words to <code>src/tools/org/h2/build/doc/dictionary.txt</code>.
</li><li>Run the <code class="notranslate">src/installer/buildRelease</code> to find and fix formatting errors. </li><li>Run the <code>src/installer/buildRelease</code> to find and fix formatting errors.
</li><li>Verify the formatting using <code class="notranslate">build docs</code> and </li><li>Verify the formatting using <code>build docs</code> and
<code class="notranslate">build javadoc</code>. <code>build javadoc</code>.
</li><li>Submit patches as <code class="notranslate">.patch</code> files (compressed if big). </li><li>Submit patches as <code>.patch</code> files (compressed if big).
To create a patch using Eclipse, use Team / Create Patch. To create a patch using Eclipse, use Team / Create Patch.
</li></ul> </li></ul>
<p> <p>
...@@ -218,7 +218,7 @@ Eclipse Public License, version 1.0 (http://h2database.com/html/license.html)." ...@@ -218,7 +218,7 @@ Eclipse Public License, version 1.0 (http://h2database.com/html/license.html)."
<p> <p>
This build process is automated and runs regularly. This build process is automated and runs regularly.
The build process includes running the tests and code coverage, using the command line The build process includes running the tests and code coverage, using the command line
<code class="notranslate">./build.sh clean jar coverage -Dh2.ftpPassword=... uploadBuild</code>. <code>./build.sh clean jar coverage -Dh2.ftpPassword=... uploadBuild</code>.
The last results are available here: The last results are available here:
</p> </p>
<ul><li><a href="http://h2database.com/html/testOutput.html">Test Output</a> <ul><li><a href="http://h2database.com/html/testOutput.html">Test Output</a>
......
...@@ -25,7 +25,7 @@ Data Types ...@@ -25,7 +25,7 @@ Data Types
<c:forEach var="item" items="dataTypes"> <c:forEach var="item" items="dataTypes">
<br /> <br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3> <h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate"> <pre>
${item.syntax} ${item.syntax}
</pre> </pre>
<p>${item.text}</p> <p>${item.text}</p>
......
...@@ -46,21 +46,21 @@ Frequently Asked Questions ...@@ -46,21 +46,21 @@ Frequently Asked Questions
Usually, bugs get fixes as they are found. There is a release every few weeks. Usually, bugs get fixes as they are found. There is a release every few weeks.
Here is the list of known and confirmed issues: Here is the list of known and confirmed issues:
</p> </p>
<ul><li>Tomcat and Glassfish 3 set most static fields (final or non-final) to null when <ul><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 class="notranslate">NullPointerException</code> in H2 versions 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 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 run into this issue. In Tomcat >= 6.0 this behavior can be disabled by setting the
system property <code class="notranslate">org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES</code> 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 to false, however Tomcat may then run out of memory. A known workaround is to
put the h2.jar file in a shared <code class="notranslate">lib</code> directory put the h2.jar file in a shared <code>lib</code> directory
(<code class="notranslate">common/lib</code>). (<code>common/lib</code>).
</li><li>Some problems have been found with right outer join. Internally, it is converted </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 to left outer join, which does not always produce the same results as other databases
when used in combination with other joins. when used in combination with other joins.
</li><li>When using Install4j before 4.1.4 on Linux and enabling 'pack200', </li><li>When using Install4j before 4.1.4 on Linux and enabling <code>pack200</code>,
the <code class="notranslate">h2*.jar</code> becomes corrupted by the install process, causing application failure. the <code>h2*.jar</code> becomes corrupted by the install process, causing application failure.
A workaround is to add an empty file <code class="notranslate">h2*.jar.nopack</code> A workaround is to add an empty file <code>h2*.jar.nopack</code>
next to the <code class="notranslate">h2*.jar</code> file. next to the <code>h2*.jar</code> file.
This problem is solved in Install4j 4.1.4. This problem is solved in Install4j 4.1.4.
</li></ul> </li></ul>
...@@ -74,15 +74,15 @@ See also under license. ...@@ -74,15 +74,15 @@ See also under license.
<br /> <br />
<h3 id="query_slow">My Query is Slow</h3> <h3 id="query_slow">My Query is Slow</h3>
<p> <p>
Slow <code class="notranslate">SELECT</code> (or <code class="notranslate">DELETE, UPDATE, MERGE</code>) Slow <code>SELECT</code> (or <code>DELETE, UPDATE, MERGE</code>)
statement can have multiple reasons. Follow this checklist: statement can have multiple reasons. Follow this checklist:
</p> </p>
<ul> <ul>
<li>Run <code class="notranslate">ANALYZE</code> (see documentation for details). <li>Run <code>ANALYZE</code> (see documentation for details).
</li><li>Run the query with <code class="notranslate">EXPLAIN</code> and check if indexes are used </li><li>Run the query with <code>EXPLAIN</code> and check if indexes are used
(see documentation for details). (see documentation for details).
</li><li>If required, create additional indexes and try again using </li><li>If required, create additional indexes and try again using
<code class="notranslate">ANALYZE</code> and <code class="notranslate">EXPLAIN</code>. <code>ANALYZE</code> and <code>EXPLAIN</code>.
</li><li>If it doesn't help please report the problem. </li><li>If it doesn't help please report the problem.
</li> </li>
</ul> </ul>
...@@ -96,11 +96,11 @@ By default, a new database is automatically created if it does not yet exist. ...@@ -96,11 +96,11 @@ By default, a new database is automatically created if it does not yet exist.
<br /> <br />
<h3 id="connect">How to Connect to a Database?</h3> <h3 id="connect">How to Connect to a Database?</h3>
<p> <p>
The database driver is <code class="notranslate">org.h2.Driver</code>, The database driver is <code>org.h2.Driver</code>,
and the database URL starts with <code class="notranslate">jdbc:h2:</code>. and the database URL starts with <code>jdbc:h2:</code>.
To connect to a database using JDBC, use the following code: To connect to a database using JDBC, use the following code:
</p> </p>
<pre class="notranslate"> <pre>
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", ""); Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
</pre> </pre>
...@@ -108,19 +108,19 @@ Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", ""); ...@@ -108,19 +108,19 @@ Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
<br /> <br />
<h3 id="database_files">Where are the Database Files Stored?</h3> <h3 id="database_files">Where are the Database Files Stored?</h3>
<p> <p>
When using database URLs like <code class="notranslate">jdbc:h2:~/test</code>, When using database URLs like <code>jdbc:h2:~/test</code>,
the database is stored in the user directory. 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 C:\Documents and Settings\&lt;userName&gt;.
If the base directory is not set (as in <code class="notranslate">jdbc:h2:test</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 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, (the current working directory). When using the H2 Console application from the start menu,
this is "&lt;Installation Directory&gt;/bin". 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 The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL
<code class="notranslate">jdbc:h2:file:data/sample</code>, the database is stored in the directory <code>jdbc:h2:file:data/sample</code>, the database is stored in the directory
<code class="notranslate">data</code> (relative to the current working 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 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). fully qualified directory name (and for Windows, drive name).
Example: <code class="notranslate">jdbc:h2:file:C:/data/test</code> Example: <code>jdbc:h2:file:C:/data/test</code>
</p> </p>
<br /> <br />
...@@ -135,7 +135,7 @@ See <a href="advanced.html#limits_limitations">Limits and Limitations</a>. ...@@ -135,7 +135,7 @@ See <a href="advanced.html#limits_limitations">Limits and Limitations</a>.
Some users have reported that after a power failure, the database can sometimes not be 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 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 (it is automatically re-created). To avoid this, append
<code class="notranslate">;LOG=2</code> to the database URL. <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 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). using the new 'page store' mechanism (currently beta).
</p> </p>
...@@ -148,13 +148,13 @@ to be dangerous, they are only supported for situations where performance is mor ...@@ -148,13 +148,13 @@ to be dangerous, they are only supported for situations where performance is mor
than reliability. Those dangerous features are: than reliability. Those dangerous features are:
</p> </p>
<ul> <ul>
<li>Disabling the transaction log mechanism using <code class="notranslate">SET LOG 0</code>. <li>Disabling the transaction log mechanism using <code>SET LOG 0</code>.
</li><li>Using the transaction isolation level <code class="notranslate">READ_UNCOMMITTED</code> </li><li>Using the transaction isolation level <code>READ_UNCOMMITTED</code>
(<code class="notranslate">LOCK_MODE 0</code>) while at the same time using multiple (<code>LOCK_MODE 0</code>) while at the same time using multiple
connections. connections.
</li><li>Disabling database file protection using <code class="notranslate">FILE_LOCK=NO</code> </li><li>Disabling database file protection using <code>FILE_LOCK=NO</code>
in the database URL. in the database URL.
</li><li>Disabling referential integrity using <code class="notranslate">SET REFERENTIAL_INTEGRITY FALSE</code>. </li><li>Disabling referential integrity using <code>SET REFERENTIAL_INTEGRITY FALSE</code>.
</li></ul> </li></ul>
<p> <p>
In addition to that, running out of memory should be avoided. In addition to that, running out of memory should be avoided.
...@@ -165,8 +165,8 @@ Areas that are not fully tested: ...@@ -165,8 +165,8 @@ Areas that are not fully tested:
</p> </p>
<ul> <ul>
<li>Platforms other than Windows XP, Linux, Mac OS X, or JVMs other than Sun 1.5 or 1.6 <li>Platforms other than Windows XP, Linux, Mac OS X, or JVMs other than Sun 1.5 or 1.6
</li><li>The features <code class="notranslate">AUTO_SERVER</code> and </li><li>The features <code>AUTO_SERVER</code> and
<code class="notranslate">AUTO_RECONNECT</code> <code>AUTO_RECONNECT</code>
</li><li>The MVCC (multi version concurrency) mode </li><li>The MVCC (multi version concurrency) mode
</li><li>Cluster mode, 2-phase commit, savepoints </li><li>Cluster mode, 2-phase commit, savepoints
</li><li>24/7 operation </li><li>24/7 operation
...@@ -181,7 +181,7 @@ Areas considered experimental are: ...@@ -181,7 +181,7 @@ Areas considered experimental are:
</p> </p>
<ul> <ul>
<li>The PostgreSQL server <li>The PostgreSQL server
</li><li>Multi-threading within the engine using <code class="notranslate">SET MULTI_THREADED=1</code> </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><li>Compatibility modes for other databases (only some features are implemented)
</li></ul> </li></ul>
...@@ -191,16 +191,16 @@ Areas considered experimental are: ...@@ -191,16 +191,16 @@ Areas considered experimental are:
If it takes a long time to open a database, in most cases it was not closed the last time. 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. This is specially a problem for larger databases.
To close a database, close all connections to it before the application ends, or execute To close a database, close all connections to it before the application ends, or execute
the command <code class="notranslate">SHUTDOWN</code>. the command <code>SHUTDOWN</code>.
The database is also closed when the virtual machine exits normally 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 Runtime.halt will prevent this.
The reason why opening is slow in this situations is that indexes are re-created. 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 If you can not guarantee the database is closed, consider using
<code class="notranslate">SET LOG 2</code> (see SQL Grammar). <code>SET LOG 2</code> (see SQL Grammar).
</p> </p>
<p> <p>
To find out what the problem is, open the database in embedded mode using the H2 Console. 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 'Creating index' lines it is an indication that the 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. database was not closed the last time.
</p> </p>
<p> <p>
......
...@@ -595,13 +595,13 @@ This is achieved using different database URLs. Settings in the URLs are not cas ...@@ -595,13 +595,13 @@ This is achieved using different database URLs. Settings in the URLs are not cas
<h2 id="embedded_databases">Connecting to an Embedded (Local) Database</h2> <h2 id="embedded_databases">Connecting to an Embedded (Local) Database</h2>
<p> <p>
The database URL for connecting to a local database is The database URL for connecting to a local database is
<code class="notranslate">jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code>. <code>jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code>.
The prefix <code class="notranslate">file:</code> is optional. If no or only a relative path is used, then the current working 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 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. operating system, however it is recommended to use lowercase letters only.
The database name must be at least three characters long The database name must be at least three characters long
(a limitation of <code class="notranslate">File.createTempFile</code>). (a limitation of <code>File.createTempFile</code>).
To point to the user home directory, use <code class="notranslate">~/</code>, as in: <code class="notranslate">jdbc:h2:~/test</code>. To point to the user home directory, use <code>~/</code>, as in: <code>jdbc:h2:~/test</code>.
</p> </p>
<br /> <br />
...@@ -613,23 +613,23 @@ This database supports the memory-only mode, where the data is not persisted. ...@@ -613,23 +613,23 @@ This database supports the memory-only mode, where the data is not persisted.
</p><p> </p><p>
In some cases, only one connection to a memory-only database is required. 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 This means the database to be opened is private. In this case, the database URL is
<code class="notranslate">jdbc:h2:mem:</code> Opening two connections within the same virtual machine <code>jdbc:h2:mem:</code> Opening two connections within the same virtual machine
means opening two different (private) databases. means opening two different (private) databases.
</p><p> </p><p>
Sometimes multiple connections to the same memory-only database are required. Sometimes multiple connections to the same memory-only database are required.
In this case, the database URL must include a name. Example: <code class="notranslate">jdbc:h2:mem:db1</code>. 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 Accessing the same database in this way only works within the same virtual machine and
class loader environment. class loader environment.
</p><p> </p><p>
It is also possible to access a memory-only database remotely 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. (or from multiple processes in the same machine) using TCP/IP or SSL/TLS.
An example database URL is: <code class="notranslate">jdbc:h2:tcp://localhost/mem:db1</code>. An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code>.
</p><p> </p><p>
By default, closing the last connection to a database closes the database. By default, closing the last connection to a database closes the database.
For an in-memory database, this means the content is lost. For an in-memory database, this means the content is lost.
To keep the database open, add <code class="notranslate">;DB_CLOSE_DELAY=-1</code> to the database URL. 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 To keep the content of an in-memory database as long as the virtual machine is alive, use
<code class="notranslate">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</code>. <code>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</code>.
</p> </p>
<br /> <br />
...@@ -654,7 +654,7 @@ and the user password; the file password itself may not contain spaces. File pas ...@@ -654,7 +654,7 @@ and the user password; the file password itself may not contain spaces. File pas
and user passwords are case sensitive. Here is an example to connect to a and user passwords are case sensitive. Here is an example to connect to a
password-encrypted database: password-encrypted database:
</p> </p>
<pre class="notranslate"> <pre>
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test;CIPHER=AES"; String url = "jdbc:h2:~/test;CIPHER=AES";
String user = "sa"; String user = "sa";
...@@ -665,13 +665,13 @@ conn = DriverManager. ...@@ -665,13 +665,13 @@ conn = DriverManager.
<h3>Encrypting or Decrypting a Database</h3> <h3>Encrypting or Decrypting a Database</h3>
<p> <p>
To encrypt an existing database, use the ChangeFileEncryption tool. 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. 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 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 'test' in the user home directory The following command line will encrypt the database <code>test</code> in the user home directory
with the file password 'filepwd' and the encryption algorithm AES: with the file password <code>filepwd</code> and the encryption algorithm AES:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.ChangeFileEncryption -dir ~ -db test -cipher AES -encrypt filepwd java -cp h2*.jar org.h2.tools.ChangeFileEncryption -dir ~ -db test -cipher AES -encrypt filepwd
</pre> </pre>
...@@ -695,10 +695,10 @@ in this case it is up to the application to protect the database files. ...@@ -695,10 +695,10 @@ in this case it is up to the application to protect the database files.
</li></ul> </li></ul>
<p> <p>
To open the database with a different file locking method, use the parameter To open the database with a different file locking method, use the parameter
<code class="notranslate">FILE_LOCK</code>. <code>FILE_LOCK</code>.
The following code opens the database with the 'socket' locking method: The following code opens the database with the 'socket' locking method:
</p> </p>
<pre class="notranslate"> <pre>
String url = "jdbc:h2:~/test;FILE_LOCK=SOCKET"; String url = "jdbc:h2:~/test;FILE_LOCK=SOCKET";
</pre> </pre>
<p> <p>
...@@ -706,7 +706,7 @@ The following code forces the database to not create a lock file at all. Please ...@@ -706,7 +706,7 @@ The following code forces the database to not create a lock file at all. Please
this is unsafe as another process is able to open the same database, possibly leading to this is unsafe as another process is able to open the same database, possibly leading to
data corruption: data corruption:
</p> </p>
<pre class="notranslate"> <pre>
String url = "jdbc:h2:~/test;FILE_LOCK=NO"; String url = "jdbc:h2:~/test;FILE_LOCK=NO";
</pre> </pre>
<p> <p>
...@@ -717,15 +717,15 @@ For more information about the algorithms, see ...@@ -717,15 +717,15 @@ For more information about the algorithms, see
<br /> <br />
<h2 id="database_only_if_exists">Opening a Database Only if it Already Exists</h2> <h2 id="database_only_if_exists">Opening a Database Only if it Already Exists</h2>
<p> <p>
By default, when an application calls <code class="notranslate">DriverManager.getConnection(url, ...)</code> 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. 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 In some situations, it is better to restrict creating new databases, and only allow to open
existing databases. To do this, add <code class="notranslate">;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 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. trying to connect. The connection only succeeds when the database already exists.
The complete URL may look like this: The complete URL may look like this:
</p> </p>
<pre class="notranslate"> <pre>
String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE"; String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE";
</pre> </pre>
...@@ -737,19 +737,19 @@ String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE"; ...@@ -737,19 +737,19 @@ String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE";
Usually, a database is closed when the last connection to it is closed. In some situations 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. 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 The automatic closing of a database can be delayed or disabled with the SQL statement
<code class="notranslate">SET DB_CLOSE_DELAY &lt;seconds&gt;</code>. <code>SET DB_CLOSE_DELAY &lt;seconds&gt;</code>.
The parameter &lt;seconds&gt; specifies the number of seconds to keep 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 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: will keep a database open for 10 seconds after the last connection was closed:
</p> </p>
<pre class="notranslate"> <pre>
SET DB_CLOSE_DELAY 10 SET DB_CLOSE_DELAY 10
</pre> </pre>
<p> <p>
The value -1 means the database is not closed automatically. 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. 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. This setting is persistent and can be set by an administrator only.
It is possible to set the value in the database URL: <code class="notranslate">jdbc:h2:~/test;DB_CLOSE_DELAY=10</code>. It is possible to set the value in the database URL: <code>jdbc:h2:~/test;DB_CLOSE_DELAY=10</code>.
</p> </p>
<br /> <br />
...@@ -764,7 +764,7 @@ The first connection (the one that is opening the database) needs to ...@@ -764,7 +764,7 @@ 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). 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: The database URL to disable database closing on exit is:
</p> </p>
<pre class="notranslate"> <pre>
String url = "jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE"; String url = "jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE";
</pre> </pre>
...@@ -779,7 +779,7 @@ In some situations, for example when using very large databases (over a few hund ...@@ -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. re-creating the index file takes very long.
In these situations it may be better to log changes to the index file, In these situations it may be better to log changes to the index file,
so that recovery from a corrupted index file is fast. so that recovery from a corrupted index file is fast.
To enable log index changes, add LOG=2 to the URL, as in <code class="notranslate">jdbc:h2:~/test;LOG=2</code>. 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. This setting should be specified when connecting.
The update performance of the database will be reduced when using this option. The update performance of the database will be reduced when using this option.
</p> </p>
...@@ -789,12 +789,12 @@ The update performance of the database will be reduced when using this option. ...@@ -789,12 +789,12 @@ The update performance of the database will be reduced when using this option.
<p> <p>
Some applications (for example OpenOffice.org Base) pass some additional parameters Some applications (for example OpenOffice.org Base) pass some additional parameters
when connecting to the database. Why those parameters are passed is unknown. when connecting to the database. Why those parameters are passed is unknown.
The parameters <code class="notranslate">PREFERDOSLIKELINEENDS</code> and The parameters <code>PREFERDOSLIKELINEENDS</code> and
<code class="notranslate">IGNOREDRIVERPRIVILEGES</code> are such examples; <code>IGNOREDRIVERPRIVILEGES</code> are such examples;
they are simply ignored to improve the compatibility with OpenOffice.org. If an application 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 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 saying the parameter is not supported. It is possible to ignored such parameters by adding
<code class="notranslate">;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL. <code>;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL.
</p> </p>
<br /> <br />
...@@ -802,8 +802,8 @@ saying the parameter is not supported. It is possible to ignored such parameters ...@@ -802,8 +802,8 @@ saying the parameter is not supported. It is possible to ignored such parameters
<p> <p>
In addition to the settings already described, In addition to the settings already described,
other database settings can be passed in the database URL. other database settings can be passed in the database URL.
Adding <code class="notranslate">;setting=value</code> at the end of a database URL is the Adding <code>;setting=value</code> at the end of a database URL is the
same as executing the statement <code class="notranslate">SET setting value</code> just after 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>. connecting. For a list of supported settings, see <a href="grammar.html">SQL Grammar</a>.
</p> </p>
...@@ -811,21 +811,21 @@ connecting. For a list of supported settings, see <a href="grammar.html">SQL Gra ...@@ -811,21 +811,21 @@ connecting. For a list of supported settings, see <a href="grammar.html">SQL Gra
<h2 id="custom_access_mode">Custom File Access Mode</h2> <h2 id="custom_access_mode">Custom File Access Mode</h2>
<p> <p>
Usually, the database opens log, data and index files with the access mode Usually, the database opens log, data and index files with the access mode
<code class="notranslate">rw</code>, meaning <code>rw</code>, meaning
read-write (except for read only databases, where the mode <code class="notranslate">r</code> is used). 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 To open a database in read-only mode if the files are not read-only, use
<code class="notranslate">ACCESS_MODE_DATA=r</code>. <code>ACCESS_MODE_DATA=r</code>.
Also supported are <code class="notranslate">rws</code> and <code class="notranslate">rwd</code>. Also supported are <code>rws</code> and <code>rwd</code>.
The access mode used for log files is set via <code class="notranslate">ACCESS_MODE_LOG</code>; The access mode used for log files is set via <code>ACCESS_MODE_LOG</code>;
for data and index files use <code class="notranslate">ACCESS_MODE_DATA</code>. for data and index files use <code>ACCESS_MODE_DATA</code>.
These settings must be specified in the database URL: These settings must be specified in the database URL:
</p> </p>
<pre class="notranslate"> <pre>
String url = "jdbc:h2:~/test;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws"; String url = "jdbc:h2:~/test;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws";
</pre> </pre>
<p> <p>
For more information see <a href="advanced.html#durability_problems">Durability Problems</a>. For more information see <a href="advanced.html#durability_problems">Durability Problems</a>.
On many operating systems the access mode 'rws' does not guarantee that the data is written to the disk. On many operating systems the access mode <code>rws</code> does not guarantee that the data is written to the disk.
</p> </p>
<br /> <br />
...@@ -866,13 +866,13 @@ then a read lock is added to the table. If there is a write lock, then this conn ...@@ -866,13 +866,13 @@ then a read lock is added to the table. If there is a write lock, then this conn
for the other connection to release the lock. If a connection cannot get a lock for a specified time, 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. then a lock timeout exception is thrown.
</p><p> </p><p>
Usually, <code class="notranslate">SELECT</code> statements will generate read locks. This includes subqueries. 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, Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data,
using the statement <code class="notranslate">SELECT ... FOR UPDATE</code>. using the statement <code>SELECT ... FOR UPDATE</code>.
The statements <code class="notranslate">COMMIT</code> and The statements <code>COMMIT</code> and
<code class="notranslate">ROLLBACK</code> releases all open locks. <code>ROLLBACK</code> releases all open locks.
The commands <code class="notranslate">SAVEPOINT</code> and The commands <code>SAVEPOINT</code> and
<code class="notranslate">ROLLBACK TO SAVEPOINT</code> don't affect locks. <code>ROLLBACK TO SAVEPOINT</code> don't affect locks.
The locks are also released when the autocommit mode changes, and for connections with 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. autocommit set to true (this is the default), locks are released after each statement.
The following statements generate locks: The following statements generate locks:
...@@ -909,9 +909,9 @@ The following statements generate locks: ...@@ -909,9 +909,9 @@ The following statements generate locks:
<p> <p>
The number of seconds until a lock timeout exception is thrown can be The number of seconds until a lock timeout exception is thrown can be
set separately for each connection using the SQL command set separately for each connection using the SQL command
<code class="notranslate">SET LOCK_TIMEOUT &lt;milliseconds&gt;</code>. <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 The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command
<code class="notranslate">SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;</code>. The default lock timeout is persistent. <code>SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;</code>. The default lock timeout is persistent.
</p> </p>
<br /> <br />
...@@ -931,7 +931,7 @@ The following files can be created by the database: ...@@ -931,7 +931,7 @@ The following files can be created by the database:
</td><td> </td><td>
Database file.<br /> Database file.<br />
Contains the data and index data for all tables.<br /> Contains the data and index data for all tables.<br />
Format: <code class="notranslate">&lt;database&gt;.h2.db</code> Format: <code>&lt;database&gt;.h2.db</code>
</td><td> </td><td>
1 per database 1 per database
</td></tr> </td></tr>
...@@ -940,7 +940,7 @@ The following files can be created by the database: ...@@ -940,7 +940,7 @@ The following files can be created by the database:
</td><td> </td><td>
Data file.<br /> Data file.<br />
Contains the data for all tables.<br /> Contains the data for all tables.<br />
Format: <code class="notranslate">&lt;database&gt;.data.db</code> Format: <code>&lt;database&gt;.data.db</code>
</td><td> </td><td>
1 per database 1 per database
</td></tr> </td></tr>
...@@ -949,7 +949,7 @@ The following files can be created by the database: ...@@ -949,7 +949,7 @@ The following files can be created by the database:
</td><td> </td><td>
Index file.<br /> Index file.<br />
Contains the data for all (b tree) indexes.<br /> Contains the data for all (b tree) indexes.<br />
Format: <code class="notranslate">&lt;database&gt;.index.db</code> Format: <code>&lt;database&gt;.index.db</code>
</td><td> </td><td>
1 per database 1 per database
</td></tr> </td></tr>
...@@ -958,7 +958,7 @@ The following files can be created by the database: ...@@ -958,7 +958,7 @@ The following files can be created by the database:
</td><td> </td><td>
Transaction log file.<br /> Transaction log file.<br />
The transaction log is used for recovery.<br /> The transaction log is used for recovery.<br />
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.log.db</code> Format: <code>&lt;database&gt;.&lt;id&gt;.log.db</code>
</td><td> </td><td>
0 or more per database 0 or more per database
</td></tr> </td></tr>
...@@ -967,7 +967,7 @@ The following files can be created by the database: ...@@ -967,7 +967,7 @@ The following files can be created by the database:
</td><td> </td><td>
Database lock file.<br /> Database lock file.<br />
Exists only while the database is open.<br /> Exists only while the database is open.<br />
Format: <code class="notranslate">&lt;database&gt;.lock.db</code> Format: <code>&lt;database&gt;.lock.db</code>
</td><td> </td><td>
1 per database 1 per database
</td></tr> </td></tr>
...@@ -976,8 +976,8 @@ The following files can be created by the database: ...@@ -976,8 +976,8 @@ The following files can be created by the database:
</td><td> </td><td>
Trace file.<br /> Trace file.<br />
Contains trace information.<br /> Contains trace information.<br />
Format: <code class="notranslate">&lt;database&gt;.trace.db</code><br /> Format: <code>&lt;database&gt;.trace.db</code><br />
If the file is too big, it is renamed to <code class="notranslate">&lt;database&gt;.trace.db.old</code> If the file is too big, it is renamed to <code>&lt;database&gt;.trace.db.old</code>
</td><td> </td><td>
1 per database 1 per database
</td></tr> </td></tr>
...@@ -986,7 +986,7 @@ The following files can be created by the database: ...@@ -986,7 +986,7 @@ The following files can be created by the database:
</td><td> </td><td>
Large object.<br /> Large object.<br />
Contains the data for BLOB or CLOB values.<br /> Contains the data for BLOB or CLOB values.<br />
Format: <code class="notranslate">&lt;id&gt;.t&lt;tableId&gt;.lob.db</code> Format: <code>&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
</td><td> </td><td>
1 per value 1 per value
</td></tr> </td></tr>
...@@ -995,7 +995,7 @@ The following files can be created by the database: ...@@ -995,7 +995,7 @@ The following files can be created by the database:
</td><td> </td><td>
Temporary file.<br /> Temporary file.<br />
Contains a temporary blob or a large result set.<br /> Contains a temporary blob or a large result set.<br />
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.temp.db</code> Format: <code>&lt;database&gt;.&lt;id&gt;.temp.db</code>
</td><td> </td><td>
1 per object 1 per object
</td></tr> </td></tr>
...@@ -1018,7 +1018,7 @@ When the database is closed, it is possible to backup the database files. Please ...@@ -1018,7 +1018,7 @@ When the database is closed, it is possible to backup the database files. Please
files do not need to be backed up, because they contain redundant data, and will be recreated files do not need to be backed up, because they contain redundant data, and will be recreated
automatically if they don't exist. automatically if they don't exist.
</p><p> </p><p>
To backup data while the database is running, the SQL command <code class="notranslate">SCRIPT</code> can be used. To backup data while the database is running, the SQL command <code>SCRIPT</code> can be used.
</p> </p>
<br /> <br />
...@@ -1035,14 +1035,14 @@ the index file is rebuilt from scratch. ...@@ -1035,14 +1035,14 @@ the index file is rebuilt from scratch.
</p><p> </p><p>
There is usually only one log file per database. This file grows until the database is closed successfully, 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). 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 class="notranslate">CHECKPOINT</code> command. It is possible to force the log switching by using the <code>CHECKPOINT</code> command.
</p><p> </p><p>
If the database file is corrupted, because the checksum of a record does not match (for example, if the 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, 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 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 and re-built as soon as possible. To open the database in the recovery mode, use a database URL
must contain <code class="notranslate">;RECOVER=1</code>, as in must contain <code>;RECOVER=1</code>, as in
<code class="notranslate">jdbc:h2:~/test;RECOVER=1</code>. Indexes are rebuilt in this case, and <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. the summary (object allocation table) is not read in this case, so opening the database takes longer.
</p> </p>
...@@ -1055,8 +1055,8 @@ and tries to be compatible to other databases. There are still a few differences ...@@ -1055,8 +1055,8 @@ and tries to be compatible to other databases. There are still a few differences
<p> <p>
In MySQL text columns are case insensitive by default, while in H2 they are case sensitive. However 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 H2 supports case insensitive columns as well. To create the tables with case insensitive texts, append
<code class="notranslate">IGNORECASE=TRUE</code> to the database URL <code>IGNORECASE=TRUE</code> to the database URL
(example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code>). (example: <code>jdbc:h2:~/test;IGNORECASE=TRUE</code>).
</p> </p>
<h3>Compatibility Modes</h3> <h3>Compatibility Modes</h3>
...@@ -1068,105 +1068,105 @@ Here is the list of currently supported modes and the differences to the regular ...@@ -1068,105 +1068,105 @@ Here is the list of currently supported modes and the differences to the regular
<h3>DB2 Compatibility Mode</h3> <h3>DB2 Compatibility Mode</h3>
<p> <p>
To use the IBM DB2 mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=DB2</code> To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code>
or the SQL statement <code class="notranslate">SET MODE DB2</code>. or the SQL statement <code>SET MODE DB2</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>Support for the syntax <code class="notranslate">[OFFSET .. ROW] [FETCH ... ONLY]</code> </li><li>Support for the syntax <code>[OFFSET .. ROW] [FETCH ... ONLY]</code>
as an alternative for <code class="notranslate">LIMIT .. OFFSET</code>. as an alternative for <code>LIMIT .. OFFSET</code>.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value </li><li>Concatenating <code>NULL</code> with another value
results in the other value. results in the other value.
</li></ul> </li></ul>
<h3>Derby Compatibility Mode</h3> <h3>Derby Compatibility Mode</h3>
<p> <p>
To use the Apache Derby mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=Derby</code> To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code>
or the SQL statement <code class="notranslate">SET MODE Derby</code>. or the SQL statement <code>SET MODE Derby</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct. </li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed. That means only one row with <code>NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value </li><li>Concatenating <code>NULL</code> with another value
results in the other value. results in the other value.
</li></ul> </li></ul>
<h3>HSQLDB Compatibility Mode</h3> <h3>HSQLDB Compatibility Mode</h3>
<p> <p>
To use the HSQLDB mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=HSQLDB</code> To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code>
or the SQL statement <code class="notranslate">SET MODE HSQLDB</code>. or the SQL statement <code>SET MODE HSQLDB</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>When converting the scale of decimal data, the number is only converted if the new scale is </li><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. smaller than the current scale. Usually, the scale is converted and 0s are added if required.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct. </li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed. That means only one row with <code>NULL</code> in one of the columns is allowed.
</li></ul> </li></ul>
<h3>MS SQL Server Compatibility Mode</h3> <h3>MS SQL Server Compatibility Mode</h3>
<p> <p>
To use the MS SQL Server mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=MSSQLServer</code> To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code>
or the SQL statement <code class="notranslate">SET MODE MSSQLServer</code>. or the SQL statement <code>SET MODE MSSQLServer</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>Identifiers may be quoted using square brackets as in <code class="notranslate">[Test]</code>. </li><li>Identifiers may be quoted using square brackets as in <code>[Test]</code>.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct. </li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed. That means only one row with <code>NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value </li><li>Concatenating <code>NULL</code> with another value
results in the other value. results in the other value.
</li></ul> </li></ul>
<h3>MySQL Compatibility Mode</h3> <h3>MySQL Compatibility Mode</h3>
<p> <p>
To use the MySQL mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=MySQL</code> To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code>
or the SQL statement <code class="notranslate">SET MODE MySQL</code>. or the SQL statement <code>SET MODE MySQL</code>.
</p> </p>
<ul><li>When inserting data, if a column is defined to be <code class="notranslate">NOT NULL</code> <ul><li>When inserting data, if a column is defined to be <code>NOT NULL</code>
and <code class="notranslate">NULL</code> is inserted, and <code>NULL</code> is inserted,
then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. 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. Usually, this operation is not allowed and an exception is thrown.
</li><li>Creating indexes in the <code class="notranslate">CREATE TABLE</code> statement is allowed. </li><li>Creating indexes in the <code>CREATE TABLE</code> statement is allowed.
</li><li>Meta data calls return identifiers in lower case. </li><li>Meta data calls return identifiers in lower case.
</li><li>When converting a floating point number to an integer, the fractional </li><li>When converting a floating point number to an integer, the fractional
digits are not truncated, but the value is rounded. digits are not truncated, but the value is rounded.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value </li><li>Concatenating <code>NULL</code> with another value
results in the other value. results in the other value.
</li></ul> </li></ul>
<h3>Oracle Compatibility Mode</h3> <h3>Oracle Compatibility Mode</h3>
<p> <p>
To use the Oracle mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=Oracle</code> To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code>
or the SQL statement <code class="notranslate">SET MODE Oracle</code>. or the SQL statement <code>SET MODE Oracle</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>When using unique indexes, multiple rows with <code class="notranslate">NULL</code> </li><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 in all columns are allowed, however it is not allowed to have multiple rows with the
same values otherwise. same values otherwise.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value </li><li>Concatenating <code>NULL</code> with another value
results in the other value. results in the other value.
</li></ul> </li></ul>
<h3>PostgreSQL Compatibility Mode</h3> <h3>PostgreSQL Compatibility Mode</h3>
<p> <p>
To use the PostgreSQL mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=PostgreSQL</code> To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code>
or the SQL statement <code class="notranslate">SET MODE PostgreSQL</code>. or the SQL statement <code>SET MODE PostgreSQL</code>.
</p> </p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code> <ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns returns the alias name and <code>getTableName()</code> returns
<code class="notranslate">null</code>. <code>null</code>.
</li><li>When converting a floating point number to an integer, the fractional </li><li>When converting a floating point number to an integer, the fractional
digits are not be truncated, but the value is rounded. digits are not be truncated, but the value is rounded.
</li><li>The system columns <code class="notranslate">CTID</code> and </li><li>The system columns <code>CTID</code> and
<code class="notranslate">OID</code> are supported. <code>OID</code> are supported.
</li></ul> </li></ul>
<br /> <br />
...@@ -1179,7 +1179,7 @@ occurs when auto-commit is enabled; if auto-commit is disabled, an exception is ...@@ -1179,7 +1179,7 @@ occurs when auto-commit is enabled; if auto-commit is disabled, an exception is
<p> <p>
Re-connecting will open a new session. After an automatic re-connect, Re-connecting will open a new session. After an automatic re-connect,
variables and local temporary tables definitions (excluding data) are re-created. variables and local temporary tables definitions (excluding data) are re-created.
The contents of the system table <code class="notranslate">INFORMATION_SCHEMA.SESSION_STATE</code> The contents of the system table <code>INFORMATION_SCHEMA.SESSION_STATE</code>
contains all client side state that is re-created. contains all client side state that is re-created.
</p> </p>
...@@ -1187,7 +1187,7 @@ contains all client side state that is re-created. ...@@ -1187,7 +1187,7 @@ contains all client side state that is re-created.
<h2 id="auto_mixed_mode">Automatic Mixed Mode</h2> <h2 id="auto_mixed_mode">Automatic Mixed Mode</h2>
<p> <p>
Multiple processes can access the same database without having to start the server manually. Multiple processes can access the same database without having to start the server manually.
To do that, append <code class="notranslate">;AUTO_SERVER=TRUE</code> to the database URL. 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. You can use the same database URL no matter if the database is already open or not.
</p> </p>
<p> <p>
...@@ -1200,14 +1200,14 @@ The application that opens the first connection to the database uses the embedde ...@@ -1200,14 +1200,14 @@ The application that opens the first connection to the database uses the embedde
which is faster than the server mode. Therefore the main application should open 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. 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, This server allows remote connections, however only to this database (to ensure that,
the client reads <code class="notranslate">.lock.db</code> file and sends the the random key that is stored there to the server). 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 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). open, one of them will then start a server (auto-reconnect is enabled automatically).
</p> </p>
<p> <p>
All processes need to have access to the database files. 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. 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 class="notranslate">jdbc:h2:tcp://</code> or <code class="notranslate">ssl://</code>) are not supported. 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. This mode is not supported for in-memory databases.
</p> </p>
<p> <p>
...@@ -1215,7 +1215,7 @@ Here is an example how to use this mode. Application 1 and 2 are not necessarily ...@@ -1215,7 +1215,7 @@ Here is an example how to use this mode. Application 1 and 2 are not necessarily
on the same computer, but they need to have access to the database files. Application 1 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). and 2 are typically two different processes (however they could run within the same process).
</p> </p>
<pre class="notranslate"> <pre>
// Application 1: // Application 1:
DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE"); DriverManager.getConnection("jdbc:h2:/data/test;AUTO_SERVER=TRUE");
...@@ -1230,8 +1230,8 @@ To find problems in an application, it is sometimes good to see what database op ...@@ -1230,8 +1230,8 @@ To find problems in an application, it is sometimes good to see what database op
where executed. This database offers the following trace features: where executed. This database offers the following trace features:
</p> </p>
<ul> <ul>
<li>Trace to <code class="notranslate">System.out</code> and/or to a file <li>Trace to <code>System.out</code> and/or to a file
</li><li>Support for trace levels <code class="notranslate">OFF, ERROR, INFO, DEBUG</code> </li><li>Support for trace levels <code>OFF, ERROR, INFO, DEBUG</code>
</li><li>The maximum size of the trace file can be set </li><li>The maximum size of the trace file can be set
</li><li>It is possible to generate Java source code from the trace file </li><li>It is possible to generate Java source code from the trace file
</li><li>Trace can be enabled at runtime by manually creating a file </li><li>Trace can be enabled at runtime by manually creating a file
...@@ -1240,26 +1240,26 @@ where executed. This database offers the following trace features: ...@@ -1240,26 +1240,26 @@ where executed. This database offers the following trace features:
<h3>Trace Options</h3> <h3>Trace Options</h3>
<p> <p>
The simplest way to enable the trace option is setting it in the database URL. The simplest way to enable the trace option is setting it in the database URL.
There are two settings, one for <code class="notranslate">System.out</code> There are two settings, one for <code>System.out</code>
(<code class="notranslate">TRACE_LEVEL_SYSTEM_OUT</code>) tracing, (<code>TRACE_LEVEL_SYSTEM_OUT</code>) tracing,
and one for file tracing (<code class="notranslate">TRACE_LEVEL_FILE</code>). and one for file tracing (<code>TRACE_LEVEL_FILE</code>).
The trace levels are The trace levels are
0 for <code class="notranslate">OFF</code>, 0 for <code>OFF</code>,
1 for <code class="notranslate">ERROR</code> (the default), 1 for <code>ERROR</code> (the default),
2 for <code class="notranslate">INFO</code>, and 2 for <code>INFO</code>, and
3 for <code class="notranslate">DEBUG</code>. 3 for <code>DEBUG</code>.
A database URL with both levels set to <code class="notranslate">DEBUG</code> is: A database URL with both levels set to <code>DEBUG</code> is:
</p> </p>
<pre class="notranslate"> <pre>
jdbc:h2:~/test;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3 jdbc:h2:~/test;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3
</pre> </pre>
<p> <p>
The trace level can be changed at runtime by executing the SQL command The trace level can be changed at runtime by executing the SQL command
<code class="notranslate">SET TRACE_LEVEL_SYSTEM_OUT level</code> (for <code class="notranslate">System.out</code> tracing) <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for <code>System.out</code> tracing)
or <code class="notranslate">SET TRACE_LEVEL_FILE level</code> (for file tracing). or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing).
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
SET TRACE_LEVEL_SYSTEM_OUT 3 SET TRACE_LEVEL_SYSTEM_OUT 3
</pre> </pre>
...@@ -1267,22 +1267,22 @@ SET TRACE_LEVEL_SYSTEM_OUT 3 ...@@ -1267,22 +1267,22 @@ SET TRACE_LEVEL_SYSTEM_OUT 3
<p> <p>
When using a high trace level, the trace file can get very big quickly. 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 The default size limit is 16 MB, if the trace file exceeds this limit, it is renamed to
<code class="notranslate">.old</code> and a new file is created. <code>.old</code> and a new file is created.
If another such file exists, it is deleted. If another such file exists, it is deleted.
To limit the size to a certain number of megabytes, use To limit the size to a certain number of megabytes, use
<code class="notranslate">SET TRACE_MAX_FILE_SIZE mb</code>. <code>SET TRACE_MAX_FILE_SIZE mb</code>.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
SET TRACE_MAX_FILE_SIZE 1 SET TRACE_MAX_FILE_SIZE 1
</pre> </pre>
<h3>Java Code Generation</h3> <h3>Java Code Generation</h3>
<p> <p>
When setting the trace level to <code class="notranslate">INFO</code> or <code class="notranslate">DEBUG</code>, 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: Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this:
</p> </p>
<pre class="notranslate"> <pre>
... ...
12-20 20:58:09 jdbc[0]: 12-20 20:58:09 jdbc[0]:
/**/dbMeta3.getURL(); /**/dbMeta3.getURL();
...@@ -1291,14 +1291,14 @@ Java source code is generated as well. This simplifies reproducing problems. The ...@@ -1291,14 +1291,14 @@ Java source code is generated as well. This simplifies reproducing problems. The
... ...
</pre> </pre>
<p> <p>
To filter the Java source code, use the <code class="notranslate">ConvertTraceFile</code> tool as follows: To filter the Java source code, use the <code>ConvertTraceFile</code> tool as follows:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.ConvertTraceFile java -cp h2*.jar org.h2.tools.ConvertTraceFile
-traceFile "~/test.trace.db" -javaClass "Test" -traceFile "~/test.trace.db" -javaClass "Test"
</pre> </pre>
<p> <p>
The generated file <code class="notranslate">Test.java</code> will contain the Java source code. 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). 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. 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. The password is not listed in the trace file and therefore not included in the source code.
...@@ -1309,7 +1309,7 @@ The password is not listed in the trace file and therefore not included in the s ...@@ -1309,7 +1309,7 @@ The password is not listed in the trace file and therefore not included in the s
<p> <p>
By default, this database uses its own native 'trace' facility. This facility is called 'trace' and not 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 'log' within this database to avoid confusion with the transaction log. Trace messages can be
written to both file and <code class="notranslate">System.out</code>. written to both file and <code>System.out</code>.
In most cases, this is sufficient, however sometimes it is better to use the same 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. facility as the application, for example Log4j. To do that, this database support SLF4J.
</p> </p>
...@@ -1322,15 +1322,15 @@ Java logging, x4juli, and Simple Log. ...@@ -1322,15 +1322,15 @@ Java logging, x4juli, and Simple Log.
<p> <p>
To enable SLF4J, set the file trace level to 4 in the database URL: To enable SLF4J, set the file trace level to 4 in the database URL:
</p> </p>
<pre class="notranslate"> <pre>
jdbc:h2:~/test;TRACE_LEVEL_FILE=4 jdbc:h2:~/test;TRACE_LEVEL_FILE=4
</pre> </pre>
<p> <p>
Changing the log mechanism is not possible after the database is open, that means Changing the log mechanism is not possible after the database is open, that means
executing the SQL statement <code class="notranslate">SET TRACE_LEVEL_FILE 4</code> executing the SQL statement <code>SET TRACE_LEVEL_FILE 4</code>
when the database is already open will not have the desired effect. 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. To use SLF4J, all required jar files need to be in the classpath.
If it does not work, check the file <code class="notranslate">&lt;database&gt;.trace.db</code> for error messages. If it does not work, check the file <code>&lt;database&gt;.trace.db</code> for error messages.
</p> </p>
<br /> <br />
...@@ -1338,23 +1338,23 @@ If it does not work, check the file <code class="notranslate">&lt;database&gt;.t ...@@ -1338,23 +1338,23 @@ If it does not work, check the file <code class="notranslate">&lt;database&gt;.t
<p> <p>
If the database files are read-only, then the database is read-only as well. 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. It is not possible to create new tables, add or modify data in this database.
Only <code class="notranslate">SELECT</code> and <code class="notranslate">CALL</code> statements are allowed. 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. 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. Then, make the database files read-only using the operating system.
When you open the database now, it is read-only. When you open the database now, it is read-only.
There are two ways an application can find out whether database is read-only: There are two ways an application can find out whether database is read-only:
by calling <code class="notranslate">Connection.isReadOnly()</code> by calling <code>Connection.isReadOnly()</code>
or by executing the SQL statement <code class="notranslate">CALL READONLY()</code>. or by executing the SQL statement <code>CALL READONLY()</code>.
</p> </p>
<br /> <br />
<h2 id="database_in_zip">Read Only Databases in Zip or Jar File</h2> <h2 id="database_in_zip">Read Only Databases in Zip or Jar File</h2>
<p> <p>
To create a read-only database in a zip file, first create a regular persistent database, and then create a backup. 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 'test', an easy way to do that is using the If you are using a database named <code>test</code>, an easy way to do that is using the
<code class="notranslate">Backup</code> tool or the <code class="notranslate">BACKUP</code> SQL statement: <code>Backup</code> tool or the <code>BACKUP</code> SQL statement:
</p> </p>
<pre class="notranslate"> <pre>
BACKUP TO 'data.zip' BACKUP TO 'data.zip'
</pre> </pre>
<p> <p>
...@@ -1362,7 +1362,7 @@ The database must not have pending changes, that means you need to close all con ...@@ -1362,7 +1362,7 @@ The database must not have pending changes, that means you need to close all con
database, open one single connection, and then execute the statement. Afterwards, you can log out, 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: and directly open the database in the zip file using the following database URL:
</p> </p>
<pre class="notranslate"> <pre>
jdbc:h2:zip:~/data.zip!/test jdbc:h2:zip:~/data.zip!/test
</pre> </pre>
<p> <p>
...@@ -1379,10 +1379,10 @@ a regular database. ...@@ -1379,10 +1379,10 @@ a regular database.
If the database needs more disk space, it calls the database event listener if one is installed. 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 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 the user has resolved the problem. To install a listener, run the SQL statement
<code class="notranslate">SET DATABASE_EVENT_LISTENER</code> or use a database URL of the form <code>SET DATABASE_EVENT_LISTENER</code> or use a database URL of the form
<code class="notranslate">jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener'</code> <code>jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener'</code>
(the quotes around the class name are required). (the quotes around the class name are required).
See also the <code class="notranslate">DatabaseEventListener</code> API. See also the <code>DatabaseEventListener</code> API.
</p> </p>
<h3>Opening a Corrupted Database</h3> <h3>Opening a Corrupted Database</h3>
...@@ -1400,7 +1400,7 @@ by using computed columns. For example, if an index on the upper-case version of ...@@ -1400,7 +1400,7 @@ 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, a column is required, create a computed column with the upper-case version of the original column,
and create an index for this column: and create an index for this column:
</p> </p>
<pre class="notranslate"> <pre>
CREATE TABLE ADDRESS( CREATE TABLE ADDRESS(
ID INT PRIMARY KEY, ID INT PRIMARY KEY,
NAME VARCHAR, NAME VARCHAR,
...@@ -1413,7 +1413,7 @@ When inserting data, it is not required (and not allowed) to specify a value for ...@@ -1413,7 +1413,7 @@ When inserting data, it is not required (and not allowed) to specify a value for
version of the column, because the value is generated. But you can use the version of the column, because the value is generated. But you can use the
column when querying the table: column when querying the table:
</p> </p>
<pre class="notranslate"> <pre>
INSERT INTO ADDRESS(ID, NAME) VALUES(1, 'Miller'); INSERT INTO ADDRESS(ID, NAME) VALUES(1, 'Miller');
SELECT * FROM ADDRESS WHERE UPPER_NAME='MILLER'; SELECT * FROM ADDRESS WHERE UPPER_NAME='MILLER';
</pre> </pre>
...@@ -1472,7 +1472,7 @@ password will not be stored in the swap file. ...@@ -1472,7 +1472,7 @@ password will not be stored in the swap file.
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: The following code can be used to do that:
</p> </p>
<pre class="notranslate"> <pre>
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
public class Test { public class Test {
...@@ -1496,18 +1496,18 @@ public class Test { ...@@ -1496,18 +1496,18 @@ public class Test {
</pre> </pre>
<p> <p>
This example requires Java 1.6. This example requires Java 1.6.
When using Swing, use <code class="notranslate">javax.swing.JPasswordField</code>. When using Swing, use <code>javax.swing.JPasswordField</code>.
</p> </p>
<h3>Passing the User Name and/or Password in the URL</h3> <h3>Passing the User Name and/or Password in the URL</h3>
<p> <p>
Instead of passing the user name as a separate parameter as in Instead of passing the user name as a separate parameter as in
<code class="notranslate"> <code>
Connection conn = DriverManager. Connection conn = DriverManager.
getConnection("jdbc:h2:~/test", "sa", "123"); getConnection("jdbc:h2:~/test", "sa", "123");
</code> </code>
the user name (and/or password) can be supplied in the URL itself: the user name (and/or password) can be supplied in the URL itself:
<code class="notranslate"> <code>
Connection conn = DriverManager. Connection conn = DriverManager.
getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123"); getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");
</code> </code>
...@@ -1523,7 +1523,7 @@ A function must be declared (registered) before it can be used. ...@@ -1523,7 +1523,7 @@ 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. Only static Java methods are supported; both the class and the method must be public.
Example Java method: Example Java method:
</p> </p>
<pre class="notranslate"> <pre>
package acme; package acme;
import java.math.*; import java.math.*;
public class Function { public class Function {
...@@ -1533,35 +1533,35 @@ public class Function { ...@@ -1533,35 +1533,35 @@ public class Function {
} }
</pre> </pre>
<p> <p>
The Java function must be registered in the database by calling <code class="notranslate">CREATE ALIAS</code>: The Java function must be registered in the database by calling <code>CREATE ALIAS</code>:
</p> </p>
<pre class="notranslate"> <pre>
CREATE ALIAS IS_PRIME FOR "acme.Function.isPrime" CREATE ALIAS IS_PRIME FOR "acme.Function.isPrime"
</pre> </pre>
<p> <p>
For a complete sample application, see <code class="notranslate">src/test/org/h2/samples/Function.java</code>. For a complete sample application, see <code>src/test/org/h2/samples/Function.java</code>.
</p> </p>
<h3>Function Data Type Mapping</h3> <h3>Function Data Type Mapping</h3>
<p> <p>
Functions that accept non-nullable parameters such as <code class="notranslate">int</code> Functions that accept non-nullable parameters such as <code>int</code>
will not be called if one of those parameters is <code class="notranslate">NULL</code>. will not be called if one of those parameters is <code>NULL</code>.
Instead, the result of the function is <code class="notranslate">NULL</code>. Instead, the result of the function is <code>NULL</code>.
If the function should be called if a parameter is <code class="notranslate">NULL</code>, you need If the function should be called if a parameter is <code>NULL</code>, you need
to use <code class="notranslate">java.lang.Integer</code> instead. to use <code>java.lang.Integer</code> instead.
</p> </p>
<p> <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>. 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 class="notranslate">java.lang.Object</code> is mapped to There are two special cases: <code>java.lang.Object</code> is mapped to
<code class="notranslate">OTHER</code> (a serialized object). Therefore, <code>OTHER</code> (a serialized object). Therefore,
<code class="notranslate">java.lang.Object</code> can not be used <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 class="notranslate">Object[]</code>: 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 class="notranslate">ARRAY</code>. arrays of any class are mapped to <code>ARRAY</code>.
</p> </p>
<h3>Functions that require a Connection</h3> <h3>Functions that require a Connection</h3>
<p> <p>
If the first parameter of a Java function is a <code class="notranslate">java.sql.Connection</code>, then the connection 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. 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 When calling the method from within the SQL statement, this connection parameter
does not need to be (can not be) specified. does not need to be (can not be) specified.
...@@ -1575,9 +1575,9 @@ and the exception is thrown to the application. ...@@ -1575,9 +1575,9 @@ and the exception is thrown to the application.
<h3>Functions returning a Result Set</h3> <h3>Functions returning a Result Set</h3>
<p> <p>
Functions may returns a result set. Such a function can be called with the <code class="notranslate">CALL</code> statement: Functions may returns a result set. Such a function can be called with the <code>CALL</code> statement:
</p> </p>
<pre class="notranslate"> <pre>
public static ResultSet query(Connection conn, String sql) throws SQLException { public static ResultSet query(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql); return conn.createStatement().executeQuery(sql);
} }
...@@ -1588,9 +1588,9 @@ CALL QUERY('SELECT * FROM TEST'); ...@@ -1588,9 +1588,9 @@ CALL QUERY('SELECT * FROM TEST');
<h3>Using SimpleResultSet</h3> <h3>Using SimpleResultSet</h3>
<p> <p>
A function can create a result set using the SimpleResultSet tool: A function can create a result set using the <code>SimpleResultSet</code> tool:
</p> </p>
<pre class="notranslate"> <pre>
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
... ...
public static ResultSet simpleResultSet() throws SQLException { public static ResultSet simpleResultSet() throws SQLException {
...@@ -1611,13 +1611,13 @@ CALL SIMPLE(); ...@@ -1611,13 +1611,13 @@ CALL SIMPLE();
A function that returns a result set can be used like a table. A function that returns a result set can be used like a table.
However, in this case the function is called at least twice: However, in this case the function is called at least twice:
first while parsing the statement to collect the column names first while parsing the statement to collect the column names
(with parameters set to null where not known at compile time). (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). 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 If the function is called just to get the column list, the URL of the connection passed to the function is
<code class="notranslate">jdbc:columnlist:connection</code>. Otherwise, the URL of the connection is <code>jdbc:columnlist:connection</code>. Otherwise, the URL of the connection is
<code class="notranslate">jdbc:default:connection</code>. <code>jdbc:default:connection</code>.
</p> </p>
<pre class="notranslate"> <pre>
public static ResultSet getMatrix(Connection conn, Integer size) public static ResultSet getMatrix(Connection conn, Integer size)
throws SQLException { throws SQLException {
SimpleResultSet rs = new SimpleResultSet(); SimpleResultSet rs = new SimpleResultSet();
...@@ -1645,12 +1645,12 @@ SELECT * FROM MATRIX(4) ORDER BY X, Y; ...@@ -1645,12 +1645,12 @@ SELECT * FROM MATRIX(4) ORDER BY X, Y;
This database supports Java triggers that are called before or after a row is updated, inserted or deleted. 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. 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. It is also possible to use triggers to simulate materialized views.
For a complete sample application, see <code class="notranslate">src/test/org/h2/samples/TriggerSample.java</code>. For a complete sample application, see <code>src/test/org/h2/samples/TriggerSample.java</code>.
A Java trigger must implement the interface <code class="notranslate">org.h2.api.Trigger</code>. The trigger class must be available 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 in the classpath of the database engine (when using the server mode, it must be in the classpath
of the server). of the server).
</p> </p>
<pre class="notranslate"> <pre>
import org.h2.api.Trigger; import org.h2.api.Trigger;
... ...
public class TriggerSample implements Trigger { public class TriggerSample implements Trigger {
...@@ -1666,24 +1666,24 @@ public class TriggerSample implements Trigger { ...@@ -1666,24 +1666,24 @@ public class TriggerSample implements Trigger {
The connection can be used to query or update data in other tables. The connection can be used to query or update data in other tables.
The trigger then needs to be defined in the database: The trigger then needs to be defined in the database:
</p> </p>
<pre class="notranslate"> <pre>
CREATE TRIGGER INV_INS AFTER INSERT ON INVOICE CREATE TRIGGER INV_INS AFTER INSERT ON INVOICE
FOR EACH ROW CALL "org.h2.samples.TriggerSample" FOR EACH ROW CALL "org.h2.samples.TriggerSample"
</pre> </pre>
<p> <p>
The trigger can be used to veto a change by throwing a <code class="notranslate">SQLException</code>. The trigger can be used to veto a change by throwing a <code>SQLException</code>.
</p> </p>
<br /> <br />
<h2 id="compacting">Compacting a Database</h2> <h2 id="compacting">Compacting a Database</h2>
<p> <p>
Empty space in the database file is re-used automatically. Empty space in the database file is re-used automatically.
To re-build the indexes, the simplest way is to delete the <code class="notranslate">.index.db</code> file 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 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 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: (compact a database). Here is a sample function to do this:
</p> </p>
<pre class="notranslate"> <pre>
public static void compact(String dir, String dbName, public static void compact(String dir, String dbName,
String user, String password) throws Exception { String user, String password) throws Exception {
String url = "jdbc:h2:" + dir + "/" + dbName; String url = "jdbc:h2:" + dir + "/" + dbName;
...@@ -1694,8 +1694,8 @@ public static void compact(String dir, String dbName, ...@@ -1694,8 +1694,8 @@ public static void compact(String dir, String dbName,
} }
</pre> </pre>
<p> <p>
See also the sample application <code class="notranslate">org.h2.samples.Compact</code>. See also the sample application <code>org.h2.samples.Compact</code>.
The commands <code class="notranslate">SCRIPT / RUNSCRIPT</code> can be used as well to create a backup 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. of a database and re-build the database from the script.
</p> </p>
...@@ -1704,16 +1704,16 @@ of a database and re-build the database from the script. ...@@ -1704,16 +1704,16 @@ of a database and re-build the database from the script.
<p> <p>
The database keeps most frequently used data and index pages in the main memory. 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 The amount of memory used for caching can be changed using the setting
<code class="notranslate">CACHE_SIZE</code>. This setting can be set in the database connection URL <code>CACHE_SIZE</code>. This setting can be set in the database connection URL
(<code class="notranslate">jdbc:h2:~/test;CACHE_SIZE=131072</code>), or it can be changed at runtime using (<code>jdbc:h2:~/test;CACHE_SIZE=131072</code>), or it can be changed at runtime using
<code class="notranslate">SET CACHE_SIZE size</code>. <code>SET CACHE_SIZE size</code>.
</p><p> </p><p>
Also supported is a second level soft reference cache. Rows in this cache are only garbage collected 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, on low memory. By default the second level cache is disabled. To enable it,
use the prefix <code class="notranslate">SOFT_</code>. Example: <code class="notranslate">jdbc:h2:~/test;CACHE_TYPE=SOFT_LRU</code>. use the prefix <code>SOFT_</code>. Example: <code>jdbc:h2:~/test;CACHE_TYPE=SOFT_LRU</code>.
</p><p> </p><p>
To get information about page reads and writes, and the current caching algorithm in use, To get information about page reads and writes, and the current caching algorithm in use,
call <code class="notranslate">SELECT * FROM INFORMATION_SCHEMA.SETTINGS</code>. The number of pages read / written call <code>SELECT * FROM INFORMATION_SCHEMA.SETTINGS</code>. The number of pages read / written
is listed for the data and index file. is listed for the data and index file.
</p> </p>
......
...@@ -56,7 +56,7 @@ Initial Developer: H2 Group ...@@ -56,7 +56,7 @@ Initial Developer: H2 Group
<a href="tutorial.html"> Tutorial </a><br /> <a href="tutorial.html"> Tutorial </a><br />
<a href="features.html"> Features </a><br /> <a href="features.html"> Features </a><br />
<a href="performance.html"> Performance </a><br /> <a href="performance.html"> Performance </a><br />
<a href="advanced.html"> Advanced Topics </a><br /> <a href="advanced.html"> Advanced </a><br />
<a href="jaqu.html"> JaQu </a><br /> <a href="jaqu.html"> JaQu </a><br />
<a href="download.html"> Download </a><br /> <a href="download.html"> Download </a><br />
<br /> <br />
...@@ -65,8 +65,8 @@ Initial Developer: H2 Group ...@@ -65,8 +65,8 @@ Initial Developer: H2 Group
<a href="functions.html"> Functions </a><br /> <a href="functions.html"> Functions </a><br />
<a href="datatypes.html"> Data Types </a><br /> <a href="datatypes.html"> Data Types </a><br />
<a href="../javadoc/index.html"> Javadoc </a><br /> <a href="../javadoc/index.html"> Javadoc </a><br />
<a href="../h2.pdf"> Docs as PDF (1 MB) </a><br />
<a href="sourceError.html"> Error Analyzer </a><br /> <a href="sourceError.html"> Error Analyzer </a><br />
<a href="../h2.pdf"> PDF (1 MB) </a><br />
<br /> <br />
<b> Appendix </b><br /> <b> Appendix </b><br />
<a href="build.html"> Build </a><br /> <a href="build.html"> Build </a><br />
......
...@@ -55,7 +55,7 @@ Functions ...@@ -55,7 +55,7 @@ Functions
<c:forEach var="item" items="functionsAll"> <c:forEach var="item" items="functionsAll">
<br /> <br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3> <h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate"> <pre>
${item.syntax} ${item.syntax}
</pre> </pre>
<p>${item.text}</p> <p>${item.text}</p>
......
...@@ -53,7 +53,7 @@ SQL Grammar ...@@ -53,7 +53,7 @@ SQL Grammar
<c:forEach var="item" items="commands"> <c:forEach var="item" items="commands">
<br /> <br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3> <h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate"> <pre>
${item.syntax} ${item.syntax}
</pre> </pre>
<p>${item.text}</p> <p>${item.text}</p>
...@@ -64,7 +64,7 @@ ${item.syntax} ...@@ -64,7 +64,7 @@ ${item.syntax}
<c:forEach var="item" items="otherGrammar"> <c:forEach var="item" items="otherGrammar">
<br /> <br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3> <h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate"> <pre>
${item.syntax} ${item.syntax}
</pre> </pre>
<p>${item.text}</p> <p>${item.text}</p>
...@@ -75,7 +75,7 @@ ${item.syntax} ...@@ -75,7 +75,7 @@ ${item.syntax}
<br /> <br />
<h3 id="information_schema" class="notranslate">Information Schema</h3> <h3 id="information_schema" class="notranslate">Information Schema</h3>
<p> <p>
The system tables in the schema <code class="notranslate">INFORMATION_SCHEMA</code> contain the meta data The system tables in the schema <code>INFORMATION_SCHEMA</code> contain the meta data
of all tables in the database as well as the current settings. of all tables in the database as well as the current settings.
</p> </p>
<table><tr><th>Table</th><th>Columns</th></tr> <table><tr><th>Table</th><th>Columns</th></tr>
...@@ -94,7 +94,7 @@ The range table is a dynamic system table that contains all values from a start ...@@ -94,7 +94,7 @@ The range table is a dynamic system table that contains all values from a start
The table contains one column called X. Both the start and end values are included in the result. The table contains one column called X. Both the start and end values are included in the result.
The table is used as follows: The table is used as follows:
</p> </p>
<pre class="notranslate"> <pre>
SELECT X FROM SYSTEM_RANGE(1, 10); SELECT X FROM SYSTEM_RANGE(1, 10);
</pre> </pre>
......
...@@ -25,7 +25,7 @@ JaQu replaces SQL, JDBC, and persistence frameworks such as Hibernate. ...@@ -25,7 +25,7 @@ JaQu replaces SQL, JDBC, and persistence frameworks such as Hibernate.
JaQu is something like LINQ for Java (LINQ stands for "language integrated query" and is a JaQu is something like LINQ for Java (LINQ stands for "language integrated query" and is a
Microsoft .NET technology). The following JaQu code: Microsoft .NET technology). The following JaQu code:
</p> </p>
<pre class="notranslate"> <pre>
Product p = new Product(); Product p = new Product();
List&lt;Product&gt; soldOutProducts = List&lt;Product&gt; soldOutProducts =
db.from(p).where(p.unitsInStock).is(0).select(); db.from(p).where(p.unitsInStock).is(0).select();
...@@ -33,7 +33,7 @@ List&lt;Product&gt; soldOutProducts = ...@@ -33,7 +33,7 @@ List&lt;Product&gt; soldOutProducts =
<p> <p>
stands for the SQL statement: stands for the SQL statement:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM PRODUCTS P SELECT * FROM PRODUCTS P
WHERE P.UNITS_IN_STOCK = 0 WHERE P.UNITS_IN_STOCK = 0
</pre> </pre>
...@@ -56,8 +56,8 @@ JaQu provides full control over when and what SQL statements are executed. ...@@ -56,8 +56,8 @@ JaQu provides full control over when and what SQL statements are executed.
<h3>Restrictions</h3> <h3>Restrictions</h3>
<p> <p>
Primitive types (eg. <code class="notranslate">boolean, int, long, double</code>) are not supported. Primitive types (eg. <code>boolean, int, long, double</code>) are not supported.
Use <code class="notranslate">java.lang.Boolean, Integer, Long, Double</code> instead. Use <code>java.lang.Boolean, Integer, Long, Double</code> instead.
</p> </p>
<h3>Why in Java?</h3> <h3>Why in Java?</h3>
...@@ -71,13 +71,13 @@ in the same application is complicated: you would need to split the application ...@@ -71,13 +71,13 @@ in the same application is complicated: you would need to split the application
Currently, JaQu is only tested with the H2 database. The API may change in future versions. Currently, JaQu is only tested with the H2 database. The API may change in future versions.
JaQu is not part of the h2 jar file, however the source code is included in H2, under: JaQu is not part of the h2 jar file, however the source code is included in H2, under:
</p> </p>
<ul><li><code class="notranslate">src/test/org/h2/test/jaqu/*</code> (samples and tests) <ul><li><code>src/test/org/h2/test/jaqu/*</code> (samples and tests)
</li><li><code class="notranslate">src/tools/org/h2/jaqu/*</code> (framework) </li><li><code>src/tools/org/h2/jaqu/*</code> (framework)
</li></ul> </li></ul>
<h2>Building the JaQu library</h2> <h2>Building the JaQu library</h2>
<p> <p>
To create the JaQu jar file, run: <code class="notranslate">build jarJaqu</code>. This will create the file <code class="notranslate">bin/h2jaqu.jar</code>. To create the JaQu jar file, run: <code>build jarJaqu</code>. This will create the file <code>bin/h2jaqu.jar</code>.
</p> </p>
<h2>Requirements</h2> <h2>Requirements</h2>
...@@ -88,7 +88,7 @@ work with any database that supports the JDBC API. ...@@ -88,7 +88,7 @@ work with any database that supports the JDBC API.
</p> </p>
<h2>Example Code</h2> <h2>Example Code</h2>
<pre class="notranslate"> <pre>
package org.h2.test.jaqu; package org.h2.test.jaqu;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
...@@ -226,10 +226,10 @@ public class Test { ...@@ -226,10 +226,10 @@ public class Test {
<p> <p>
JaQu does not require any configuration when using the default mapping. JaQu does not require any configuration when using the default mapping.
To define table indices, or if you want to map a class to a table with a different name, To define table indices, or if you want to map a class to a table with a different name,
or a field to a column with another name, create a function called 'define' in the data class. or a field to a column with another name, create a function called <code>define</code> in the data class.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
public class Product implements Table { public class Product implements Table {
public Integer productId; public Integer productId;
...@@ -247,7 +247,7 @@ public class Product implements Table { ...@@ -247,7 +247,7 @@ public class Product implements Table {
} }
</pre> </pre>
<p> <p>
The method <code class="notranslate">define()</code> contains the mapping definition. It is called once The method <code>define()</code> contains the mapping definition. It is called once
when the class is used for the first time. Like annotations, the mapping is defined in the class itself. when the class is used for the first time. Like annotations, the mapping is defined in the class itself.
Unlike when using annotations, the compiler can check the syntax even for multi-column Unlike when using annotations, the compiler can check the syntax even for multi-column
objects (multi-column indexes, multi-column primary keys and so on). objects (multi-column indexes, multi-column primary keys and so on).
...@@ -262,7 +262,7 @@ To do that, the condition class is de-compiled to a SQL condition. ...@@ -262,7 +262,7 @@ To do that, the condition class is de-compiled to a SQL condition.
A proof of concept decompiler is included (but it doesn't work yet). A proof of concept decompiler is included (but it doesn't work yet).
The planned syntax is: The planned syntax is:
</p> </p>
<pre class="notranslate"> <pre>
long count = db.from(co). long count = db.from(co).
where(new Filter() { public boolean where() { where(new Filter() { public boolean where() {
return co.id == x return co.id == x
......
...@@ -37,7 +37,7 @@ There is a License FAQ for both the MPL and the EPL, most of that is applicable ...@@ -37,7 +37,7 @@ There is a License FAQ for both the MPL and the EPL, most of that is applicable
However, nobody is allowed to rename H2, modify it a little, and sell it as a database engine without telling the customers it is in fact H2. However, nobody is allowed to rename H2, modify it a little, and sell it as a database engine without telling the customers it is in fact H2.
This happened to HSQLDB: a company called 'bungisoft' copied HSQLDB, renamed it to 'RedBase', and tried to sell it, This happened to HSQLDB: a company called 'bungisoft' copied HSQLDB, renamed it to 'RedBase', and tried to sell it,
hiding the fact that it was in fact just HSQLDB. It seems 'bungisoft' does not exist any more, but you can use the hiding the fact that it was in fact just HSQLDB. It seems 'bungisoft' does not exist any more, but you can use the
Wayback Machine of http://www.archive.org and visit old web pages of http://www.bungisoft.com . <a href="http://www.archive.org">Wayback Machine</a> and visit old web pages of <code>http://www.bungisoft.com</code>.
</p><p> </p><p>
About porting the source code to another language (for example C# or C++): converted source code (even if done manually) stays under the same About porting the source code to another language (for example C# or C++): converted source code (even if done manually) stays under the same
copyright and license as the original code. The copyright of the ported source code does not (automatically) go to the person who ported the code. copyright and license as the original code. The copyright of the ported source code does not (automatically) go to the person who ported the code.
......
...@@ -102,12 +102,12 @@ some time after opening a database to ensure the database files are not opened b ...@@ -102,12 +102,12 @@ some time after opening a database to ensure the database files are not opened b
<p> <p>
Version 1.8.0.10 was used for the test. Version 1.8.0.10 was used for the test.
Cached tables are used in this test (hsqldb.default_table_type=cached), Cached tables are used in this test (hsqldb.default_table_type=cached),
and the write delay is 1 second (<code class="notranslate">SET WRITE_DELAY 1</code>). and the write delay is 1 second (<code>SET WRITE_DELAY 1</code>).
HSQLDB is fast when using simple operations. HSQLDB is fast when using simple operations.
HSQLDB is very slow in the last test (BenchC: Transactions), probably because is has a bad query optimizer. HSQLDB is very slow in the last test (BenchC: Transactions), probably because is has a bad query optimizer.
One query where HSQLDB is slow is a two-table join: One query where HSQLDB is slow is a two-table join:
</p> </p>
<pre class="notranslate"> <pre>
SELECT COUNT(DISTINCT S_I_ID) FROM ORDER_LINE, STOCK SELECT COUNT(DISTINCT S_I_ID) FROM ORDER_LINE, STOCK
WHERE OL_W_ID=? AND OL_D_ID=? AND OL_O_ID&lt;? AND OL_O_ID&gt;=? WHERE OL_W_ID=? AND OL_D_ID=? AND OL_O_ID&lt;? AND OL_O_ID&gt;=?
AND S_W_ID=? AND S_I_ID=OL_I_ID AND S_QUANTITY&lt;? AND S_W_ID=? AND S_I_ID=OL_I_ID AND S_QUANTITY&lt;?
...@@ -125,7 +125,7 @@ This seems to be a structural problem, because all operations are really slow. ...@@ -125,7 +125,7 @@ This seems to be a structural problem, because all operations are really slow.
It will be hard for the developers of Derby to improve the performance to a reasonable level. It will be hard for the developers of Derby to improve the performance to a reasonable level.
A few problems have been identified: leaving autocommit on is a problem for Derby. A few problems have been identified: leaving autocommit on is a problem for Derby.
If it is switched off during the whole test, the results are about 20% better for Derby. If it is switched off during the whole test, the results are about 20% better for Derby.
Derby supports a testing mode (system property <code class="notranslate">derby.system.durability=test</code>) where durability is Derby supports a testing mode (system property <code>derby.system.durability=test</code>) where durability is
disabled. According to the documentation, this setting should be used for testing only, disabled. According to the documentation, this setting should be used for testing only,
as the database may not recover after a crash. Enabling this setting improves performance as the database may not recover after a crash. Enabling this setting improves performance
by a factor of 2.6 (embedded mode) or 1.4 (server mode). Even if enabled, Derby is still less by a factor of 2.6 (embedded mode) or 1.4 (server mode). Even if enabled, Derby is still less
...@@ -135,7 +135,7 @@ than half as fast as H2 in default mode. ...@@ -135,7 +135,7 @@ than half as fast as H2 in default mode.
<h4>PostgreSQL</h4> <h4>PostgreSQL</h4>
<p> <p>
Version 8.3.7 was used for the test. Version 8.3.7 was used for the test.
The following options where changed in <code class="notranslate">postgresql.conf: The following options where changed in <code>postgresql.conf:
fsync = off, commit_delay = 1000</code>. fsync = off, commit_delay = 1000</code>.
PostgreSQL is run in server mode. It looks like the base performance is slower than PostgreSQL is run in server mode. It looks like the base performance is slower than
MySQL, the reason could be the network layer. MySQL, the reason could be the network layer.
...@@ -146,14 +146,14 @@ The memory usage number is incorrect, because only the memory usage of the JDBC ...@@ -146,14 +146,14 @@ The memory usage number is incorrect, because only the memory usage of the JDBC
<p> <p>
Version 5.1.34-community was used for the test. Version 5.1.34-community was used for the test.
MySQL was run with the InnoDB backend. MySQL was run with the InnoDB backend.
The setting <code class="notranslate">innodb_flush_log_at_trx_commit</code> The setting <code>innodb_flush_log_at_trx_commit</code>
(found in the <code class="notranslate">my.ini</code> file) was set to 0. Otherwise (and by default), MySQL is really slow (found in the <code>my.ini</code> file) was set to 0. Otherwise (and by default), MySQL is really slow
(around 140 statements per second in this test) because it tries to flush the data to disk for each commit. (around 140 statements per second in this test) because it tries to flush the data to disk for each commit.
For small transactions (when autocommit is on) this is really slow. For small transactions (when autocommit is on) this is really slow.
But many use cases use small or relatively small transactions. But many use cases use small or relatively small transactions.
Too bad this setting is not listed in the configuration wizard, Too bad this setting is not listed in the configuration wizard,
and it always overwritten when using the wizard. and it always overwritten when using the wizard.
You need to change this setting manually in the file <code class="notranslate">my.ini</code>, and then restart the service. You need to change this setting manually in the file <code>my.ini</code>, and then restart the service.
The memory usage number is incorrect, because only the memory usage of the JDBC driver is measured. The memory usage number is incorrect, because only the memory usage of the JDBC driver is measured.
</p> </p>
...@@ -178,7 +178,7 @@ SQLite was not tested because the JDBC driver doesn't support transactions. ...@@ -178,7 +178,7 @@ SQLite was not tested because the JDBC driver doesn't support transactions.
<p> <p>
This test was executed as follows: This test was executed as follows:
</p> </p>
<pre class="notranslate"> <pre>
build benchmark build benchmark
</pre> </pre>
...@@ -246,8 +246,8 @@ each database tested, and each database runs in a different process (sequentiall ...@@ -246,8 +246,8 @@ each database tested, and each database runs in a different process (sequentiall
<h4>Transaction Commit / Durability</h4> <h4>Transaction Commit / Durability</h4>
<p> <p>
Durability means transaction committed to the database will not be lost. Durability means transaction committed to the database will not be lost.
Some databases (for example MySQL) try to enforce this by default by Some databases (for example MySQL) try to enforce this by default by
calling <code class="notranslate">fsync()</code> to flush the buffers, but calling <code>fsync()</code> to flush the buffers, but
most hard drives don't actually flush all data. Calling the method slows down transaction commit a lot, most hard drives don't actually flush all data. Calling the method slows down transaction commit a lot,
but doesn't always make data durable. When comparing the results, it is important to but doesn't always make data durable. When comparing the results, it is important to
think about the effect. Many database suggest to 'batch' operations when possible. think about the effect. Many database suggest to 'batch' operations when possible.
...@@ -307,13 +307,13 @@ There are a few problems with the PolePosition test: ...@@ -307,13 +307,13 @@ There are a few problems with the PolePosition test:
<ul><li> <ul><li>
HSQLDB uses in-memory tables by default while H2 uses persistent tables. The HSQLDB version HSQLDB uses in-memory tables by default while H2 uses persistent tables. The HSQLDB version
included in PolePosition does not support changing this, so you need to replace included in PolePosition does not support changing this, so you need to replace
<code class="notranslate">poleposition-0.20/lib/hsqldb.jar</code> with a newer version (for example <code>poleposition-0.20/lib/hsqldb.jar</code> with a newer version (for example
<code class="notranslate">hsqldb-1.8.0.7.jar</code>), <code>hsqldb-1.8.0.7.jar</code>),
and then use the setting and then use the setting
<code class="notranslate">hsqldb.connecturl=jdbc:hsqldb:file:data/hsqldb/dbbench2;hsqldb.default_table_type=cached;sql.enforce_size=true</code> <code>hsqldb.connecturl=jdbc:hsqldb:file:data/hsqldb/dbbench2;hsqldb.default_table_type=cached;sql.enforce_size=true</code>
in the file <code class="notranslate">Jdbc.properties</code>. in the file <code>Jdbc.properties</code>.
</li><li>HSQLDB keeps the database open between tests, while H2 closes the database (losing all the cache). </li><li>HSQLDB keeps the database open between tests, while H2 closes the database (losing all the cache).
To change that, use the database URL <code class="notranslate">jdbc:h2:file:data/h2/dbbench;DB_CLOSE_DELAY=-1</code> To change that, use the database URL <code>jdbc:h2:file:data/h2/dbbench;DB_CLOSE_DELAY=-1</code>
</li><li>The amount of cache memory is quite important, specially for the PolePosition test. </li><li>The amount of cache memory is quite important, specially for the PolePosition test.
Unfortunately, the PolePosition test does not take this into account. Unfortunately, the PolePosition test does not take this into account.
</li></ul> </li></ul>
...@@ -326,7 +326,7 @@ Unfortunately, the PolePosition test does not take this into account. ...@@ -326,7 +326,7 @@ Unfortunately, the PolePosition test does not take this into account.
Before trying to optimize performance, it is important to understand where the problem is (what part of the application is slow). Before trying to optimize performance, it is important to understand where the problem is (what part of the application is slow).
Blind optimization or optimization based on guesses should be avoided, because usually it is not an efficient strategy. Blind optimization or optimization based on guesses should be avoided, because usually it is not an efficient strategy.
There are various ways to analyze an application. Sometimes two implementations can be compared using There are various ways to analyze an application. Sometimes two implementations can be compared using
<code class="notranslate">System.currentTimeMillis()</code>. But this does not work for complex applications with many modules, and for memory problems. <code>System.currentTimeMillis()</code>. But this does not work for complex applications with many modules, and for memory problems.
</p> </p>
<p> <p>
A good tool to measure both memory usage and performance is the A good tool to measure both memory usage and performance is the
...@@ -335,24 +335,24 @@ A good tool to measure both memory usage and performance is the ...@@ -335,24 +335,24 @@ A good tool to measure both memory usage and performance is the
<p> <p>
A simple way to profile an application is to use the built-in profiling tool of java. Example: A simple way to profile an application is to use the built-in profiling tool of java. Example:
</p> </p>
<pre class="notranslate"> <pre>
java -Xrunhprof:cpu=samples,depth=16 com.acme.Test java -Xrunhprof:cpu=samples,depth=16 com.acme.Test
</pre> </pre>
<p> <p>
Unfortunately, it is only possible to profile the application from start to end. Another solution is to create Unfortunately, it is only possible to profile the application from start to end. Another solution is to create
a number of full thread dumps. To do that, first run <code class="notranslate">jps -l</code> to get the process id, and then a number of full thread dumps. To do that, first run <code>jps -l</code> to get the process id, and then
run <code class="notranslate">jstack &lt;pid&gt;</code> or <code class="notranslate">kill -QUIT &lt;pid&gt;</code> (Linux) or press run <code>jstack &lt;pid&gt;</code> or <code>kill -QUIT &lt;pid&gt;</code> (Linux) or press
Ctrl+C (Windows). Ctrl+C (Windows).
</p> </p>
<br /> <br />
<h2 id="database_profiling">Database Profiling</h2> <h2 id="database_profiling">Database Profiling</h2>
<p> <p>
The <code class="notranslate">ConvertTraceFile</code> tool generates SQL statement statistics at the end of the SQL script file. The <code>ConvertTraceFile</code> tool generates SQL statement statistics at the end of the SQL script file.
The format used is similar to the profiling data generated when using <code class="notranslate">java -Xrunhprof</code>. The format used is similar to the profiling data generated when using <code>java -Xrunhprof</code>.
As an example, execute the the following script using the H2 Console: As an example, execute the the following script using the H2 Console:
</p> </p>
<pre class="notranslate"> <pre>
SET TRACE_LEVEL_FILE 3; SET TRACE_LEVEL_FILE 3;
DROP TABLE IF EXISTS TEST; DROP TABLE IF EXISTS TEST;
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255)); CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
...@@ -360,17 +360,17 @@ CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255)); ...@@ -360,17 +360,17 @@ CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
SET TRACE_LEVEL_FILE 0; SET TRACE_LEVEL_FILE 0;
</pre> </pre>
<p> <p>
Now convert the <code class="notranslate">.trace.db</code> file using the <code class="notranslate">ConvertTraceFile</code> tool: Now convert the <code>.trace.db</code> file using the <code>ConvertTraceFile</code> tool:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.ConvertTraceFile java -cp h2*.jar org.h2.tools.ConvertTraceFile
-traceFile "~/test.trace.db" -script "~/test.sql" -traceFile "~/test.trace.db" -script "~/test.sql"
</pre> </pre>
<p> <p>
The generated file <code class="notranslate">test.sql</code> will contain the SQL statements as well as the The generated file <code>test.sql</code> will contain the SQL statements as well as the
following profiling data (results vary): following profiling data (results vary):
</p> </p>
<pre class="notranslate"> <pre>
----------------------------------------- -----------------------------------------
-- SQL Statement Statistics -- SQL Statement Statistics
-- time: total time in milliseconds (accumulated) -- time: total time in milliseconds (accumulated)
...@@ -390,7 +390,7 @@ following profiling data (results vary): ...@@ -390,7 +390,7 @@ following profiling data (results vary):
<h3>Use a Modern JVM</h3> <h3>Use a Modern JVM</h3>
<p> <p>
Newer JVMs are faster. Upgrading to the latest version of your JVM can provide a "free" boost to performance. Newer JVMs are faster. Upgrading to the latest version of your JVM can provide a "free" boost to performance.
Switching from the default Client JVM to the Server JVM using the <code class="notranslate">-server</code> command-line Switching from the default Client JVM to the Server JVM using the <code>-server</code> command-line
option improves performance at the cost of a slight increase in start-up time. option improves performance at the cost of a slight increase in start-up time.
</p> </p>
...@@ -401,7 +401,7 @@ It is very important for performance that database files are not scanned for vir ...@@ -401,7 +401,7 @@ It is very important for performance that database files are not scanned for vir
The database engine never interprets the data stored in the files as programs, The database engine never interprets the data stored in the files as programs,
that means even if somebody would store a virus in a database file, this would that means even if somebody would store a virus in a database file, this would
be harmless (when the virus does not run, it cannot spread). be harmless (when the virus does not run, it cannot spread).
Some virus scanners allow to exclude files by suffix. Ensure files ending with <code class="notranslate">.db</code> are not scanned. Some virus scanners allow to exclude files by suffix. Ensure files ending with <code>.db</code> are not scanned.
</p> </p>
<h3>Using the Trace Options</h3> <h3>Using the Trace Options</h3>
...@@ -415,16 +415,16 @@ For more information, see <a href="features.html#trace_options">Using the Trace ...@@ -415,16 +415,16 @@ For more information, see <a href="features.html#trace_options">Using the Trace
<h3>Index Usage</h3> <h3>Index Usage</h3>
<p> <p>
This database uses indexes to improve the performance of This database uses indexes to improve the performance of
<code class="notranslate">SELECT, UPDATE, DELETE</code>. <code>SELECT, UPDATE, DELETE</code>.
If a column is used in the <code class="notranslate">WHERE</code> clause of a query, and if an index exists on this column, If a column is used in the <code>WHERE</code> clause of a query, and if an index exists on this column,
then the index can be used. Multi-column indexes are used if all or the first columns of the index are used. then the index can be used. Multi-column indexes are used if all or the first columns of the index are used.
Both equality lookup and range scans are supported. Both equality lookup and range scans are supported.
Indexes are used to order result sets, but only if the condition uses the same index or no index at all. Indexes are used to order result sets, but only if the condition uses the same index or no index at all.
The results are sorted in memory if required. The results are sorted in memory if required.
Indexes are created automatically for primary key and unique constraints. Indexes are created automatically for primary key and unique constraints.
Indexes are also created for foreign key constraints, if required. Indexes are also created for foreign key constraints, if required.
For other columns, indexes need to be created manually using the <code class="notranslate">CREATE INDEX</code> statement. For other columns, indexes need to be created manually using the <code>CREATE INDEX</code> statement.
</p> </p>
<h3>Optimizer</h3> <h3>Optimizer</h3>
...@@ -442,34 +442,34 @@ Only left-deep plans are evaluated. ...@@ -442,34 +442,34 @@ Only left-deep plans are evaluated.
After the statement is parsed, all expressions are simplified automatically if possible. Operations After the statement is parsed, all expressions are simplified automatically if possible. Operations
are evaluated only once if all parameters are constant. Functions are also optimized, but only are evaluated only once if all parameters are constant. Functions are also optimized, but only
if the function is constant (always returns the same result for the same parameter values). if the function is constant (always returns the same result for the same parameter values).
If the <code class="notranslate">WHERE</code> clause is always false, then the table is not accessed at all. If the <code>WHERE</code> clause is always false, then the table is not accessed at all.
</p> </p>
<h3>COUNT(*) Optimization</h3> <h3>COUNT(*) Optimization</h3>
<p> <p>
If the query only counts all rows of a table, then the data is not accessed. If the query only counts all rows of a table, then the data is not accessed.
However, this is only possible if no <code class="notranslate">WHERE</code> clause is used, that means it only works for However, this is only possible if no <code>WHERE</code> clause is used, that means it only works for
queries of the form <code class="notranslate">SELECT COUNT(*) FROM table</code>. queries of the form <code>SELECT COUNT(*) FROM table</code>.
</p> </p>
<h3>Updating Optimizer Statistics / Column Selectivity</h3> <h3>Updating Optimizer Statistics / Column Selectivity</h3>
<p> <p>
When executing a query, at most one index per joined table can be used. When executing a query, at most one index per joined table can be used.
If the same table is joined multiple times, for each join only one index is used. If the same table is joined multiple times, for each join only one index is used.
Example: for the query Example: for the query
<code class="notranslate">SELECT * FROM TEST T1, TEST T2 WHERE T1.NAME='A' AND T2.ID=T1.ID</code>, <code>SELECT * FROM TEST T1, TEST T2 WHERE T1.NAME='A' AND T2.ID=T1.ID</code>,
two index can be used, in this case the index on NAME for T1 and the index on ID for T2. two index can be used, in this case the index on NAME for T1 and the index on ID for T2.
</p><p> </p><p>
If a table has multiple indexes, sometimes more than one index could be used. If a table has multiple indexes, sometimes more than one index could be used.
Example: if there is a table <code class="notranslate">TEST(ID, NAME, FIRSTNAME)</code> and an index on each column, Example: if there is a table <code>TEST(ID, NAME, FIRSTNAME)</code> and an index on each column,
then two indexes could be used for the query <code class="notranslate">SELECT * FROM TEST WHERE NAME='A' AND FIRSTNAME='B'</code>, then two indexes could be used for the query <code>SELECT * FROM TEST WHERE NAME='A' AND FIRSTNAME='B'</code>,
the index on NAME or the index on FIRSTNAME. It is not possible to use both indexes at the same time. the index on NAME or the index on FIRSTNAME. It is not possible to use both indexes at the same time.
Which index is used depends on the selectivity of the column. The selectivity describes the 'uniqueness' of Which index is used depends on the selectivity of the column. The selectivity describes the 'uniqueness' of
values in a column. A selectivity of 100 means each value appears only once, and a selectivity of 1 means values in a column. A selectivity of 100 means each value appears only once, and a selectivity of 1 means
the same value appears in many or most rows. For the query above, the index on NAME should be used the same value appears in many or most rows. For the query above, the index on NAME should be used
if the table contains more distinct names than first names. if the table contains more distinct names than first names.
</p><p> </p><p>
The SQL statement <code class="notranslate">ANALYZE</code> can be used to automatically estimate the selectivity of the columns in the tables. The SQL statement <code>ANALYZE</code> can be used to automatically estimate the selectivity of the columns in the tables.
This command should be run from time to time to improve the query plans generated by the optimizer. This command should be run from time to time to improve the query plans generated by the optimizer.
</p> </p>
...@@ -480,21 +480,21 @@ queries and data manipulation. ...@@ -480,21 +480,21 @@ queries and data manipulation.
</p> </p>
<p>In-memory indexes are automatically used <p>In-memory indexes are automatically used
for in-memory databases, but can also be created for persistent databases for in-memory databases, but can also be created for persistent databases
using <code class="notranslate">CREATE MEMORY TABLE</code>. In many cases, using <code>CREATE MEMORY TABLE</code>. In many cases,
the rows itself will also be kept in-memory. Please note this may cause memory the rows itself will also be kept in-memory. Please note this may cause memory
problems for large tables. problems for large tables.
</p> </p>
<p> <p>
In-memory hash indexes are backed by a hash table and are usually faster than In-memory hash indexes are backed by a hash table and are usually faster than
regular indexes. However, hash indexes only supports direct lookup (<code class="notranslate">WHERE ID = ?</code>) regular indexes. However, hash indexes only supports direct lookup (<code>WHERE ID = ?</code>)
but not range scan (<code class="notranslate">WHERE ID &lt; ?</code>). To use hash indexes, use HASH as in: but not range scan (<code>WHERE ID &lt; ?</code>). To use hash indexes, use HASH as in:
<code class="notranslate">CREATE UNIQUE HASH INDEX</code> and <code>CREATE UNIQUE HASH INDEX</code> and
<code class="notranslate">CREATE TABLE ...(ID INT PRIMARY KEY HASH,...)</code>. <code>CREATE TABLE ...(ID INT PRIMARY KEY HASH,...)</code>.
</p> </p>
<h3>Optimization Examples</h3> <h3>Optimization Examples</h3>
<p> <p>
See <code class="notranslate">src/test/org/h2/samples/optimizations.sql</code> for a few examples of queries See <code>src/test/org/h2/samples/optimizations.sql</code> for a few examples of queries
that benefit from special optimizations built into the database. that benefit from special optimizations built into the database.
</p> </p>
...@@ -508,17 +508,17 @@ the second level soft reference cache. See also <a href="features.html#cache_set ...@@ -508,17 +508,17 @@ the second level soft reference cache. See also <a href="features.html#cache_set
<p> <p>
Each data type has different storage and performance characteristics: Each data type has different storage and performance characteristics:
</p> </p>
<ul><li>The <code class="notranslate">DECIMAL/NUMERIC</code> type is slower <ul><li>The <code>DECIMAL/NUMERIC</code> type is slower
and requires more storage than the <code class="notranslate">REAL</code> and <code class="notranslate">DOUBLE</code> types. and requires more storage than the <code>REAL</code> and <code>DOUBLE</code> types.
</li><li>Text types are slower to read, write, and compare than numeric types and generally require more storage. </li><li>Text types are slower to read, write, and compare than numeric types and generally require more storage.
</li><li>See <a href="advanced.html#large_objects">Large Objects</a> for information on </li><li>See <a href="advanced.html#large_objects">Large Objects</a> for information on
<code class="notranslate">BINARY</code> vs. <code class="notranslate">BLOB</code> <code>BINARY</code> vs. <code>BLOB</code>
and <code class="notranslate">VARCHAR</code> vs. <code class="notranslate">CLOB</code> performance. and <code>VARCHAR</code> vs. <code>CLOB</code> performance.
</li><li>Parsing and formatting takes longer for the </li><li>Parsing and formatting takes longer for the
<code class="notranslate">TIME</code>, <code class="notranslate">DATE</code>, and <code>TIME</code>, <code>DATE</code>, and
<code class="notranslate">TIMESTAMP</code> types than the numeric types. <code>TIMESTAMP</code> types than the numeric types.
</li><li><code class="notranslate">SMALLINT/TINYINT/BOOLEAN</code> are not significantly smaller or faster </li><li><code>SMALLINT/TINYINT/BOOLEAN</code> are not significantly smaller or faster
to work with than <code class="notranslate">INTEGER</code> in most modes. to work with than <code>INTEGER</code> in most modes.
</li></ul> </li></ul>
<br /> <br />
...@@ -526,14 +526,14 @@ Each data type has different storage and performance characteristics: ...@@ -526,14 +526,14 @@ Each data type has different storage and performance characteristics:
<p> <p>
To speed up large imports, consider using the following options temporarily: To speed up large imports, consider using the following options temporarily:
</p> </p>
<ul><li><code class="notranslate">SET CACHE_SIZE</code> (a large cache is faster) <ul><li><code>SET CACHE_SIZE</code> (a large cache is faster)
</li><li><code class="notranslate">SET LOCK_MODE 0</code> (disable locking) </li><li><code>SET LOCK_MODE 0</code> (disable locking)
</li><li><code class="notranslate">SET LOG 0</code> (disable the transaction log) </li><li><code>SET LOG 0</code> (disable the transaction log)
</li><li><code class="notranslate">SET UNDO_LOG 0</code> (disable the session undo log) </li><li><code>SET UNDO_LOG 0</code> (disable the session undo log)
</li></ul> </li></ul>
<p> <p>
These options can be set in the database URL: These options can be set in the database URL:
<code class="notranslate">jdbc:h2:~/test;CACHE_SIZE=65536;LOCK_MODE=0;LOG=0;UNDO_LOG=0</code>. <code>jdbc:h2:~/test;CACHE_SIZE=65536;LOCK_MODE=0;LOG=0;UNDO_LOG=0</code>.
Most of those options are not recommended for regular use, that means you need to reset them after use. Most of those options are not recommended for regular use, that means you need to reset them after use.
</p> </p>
......
...@@ -27,9 +27,9 @@ Quickstart ...@@ -27,9 +27,9 @@ Quickstart
This database can be used in embedded mode, or in server mode. To use it in embedded mode, you need to: This database can be used in embedded mode, or in server mode. To use it in embedded mode, you need to:
</p> </p>
<ul> <ul>
<li>Add the <code class="notranslate">h2*.jar</code> to the classpath (H2 does not have any dependencies) <li>Add the <code>h2*.jar</code> to the classpath (H2 does not have any dependencies)
</li><li>Use the JDBC driver class: <code class="notranslate">org.h2.Driver</code> </li><li>Use the JDBC driver class: <code>org.h2.Driver</code>
</li><li>The database URL <code class="notranslate">jdbc:h2:~/test</code> opens the database 'test' in your user home directory </li><li>The database URL <code>jdbc:h2:~/test</code> opens the database <code>test</code> in your user home directory
</li><li>A new database is automatically created </li><li>A new database is automatically created
</li></ul> </li></ul>
......
...@@ -76,31 +76,31 @@ Depending on your platform and environment, there are multiple ways to start the ...@@ -76,31 +76,31 @@ Depending on your platform and environment, there are multiple ways to start the
<img src="images/db-16.png" alt="[H2 icon]" /><br /> <img src="images/db-16.png" alt="[H2 icon]" /><br />
If you don't get the window and the system tray icon, If you don't get the window and the system tray icon,
then maybe Java is not installed correctly (in this case, try another way to start the application). then maybe Java is not installed correctly (in this case, try another way to start the application).
A browser window should open and point to the Login page at <code class="notranslate">http://localhost:8082</code>. A browser window should open and point to the Login page at <code>http://localhost:8082</code>.
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Windows</td> <td>Windows</td>
<td> <td>
Open a file browser, navigate to <code class="notranslate">h2/bin</code>, and Open a file browser, navigate to <code>h2/bin</code>, and
double click on <code class="notranslate">h2.bat</code>.<br /> double click on <code>h2.bat</code>.<br />
A console window appears. If there is a problem, you will see an error message A console window appears. If there is a problem, you will see an error message
in this window. A browser window will open and point to the Login page in this window. A browser window will open and point to the Login page
(URL: <code class="notranslate">http://localhost:8082</code>). (URL: <code>http://localhost:8082</code>).
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Any</td> <td>Any</td>
<td> <td>
Double click on the <code class="notranslate">h2*.jar</code> file. Double click on the <code>h2*.jar</code> file.
This only works if the <code class="notranslate">.jar</code> suffix is associated with java. This only works if the <code>.jar</code> suffix is associated with java.
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Any</td> <td>Any</td>
<td> <td>
Open a console window, navigate to the directory <code class="notranslate">h2/bin</code> and type: Open a console window, navigate to the directory <code>h2/bin</code> and type:
<pre class="notranslate">java -cp h2*.jar org.h2.tools.Server</pre> <pre>java -cp h2*.jar org.h2.tools.Server</pre>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -127,7 +127,7 @@ To change this, go to 'Preferences' and select 'Allow connections from other com ...@@ -127,7 +127,7 @@ To change this, go to 'Preferences' and select 'Allow connections from other com
<p> <p>
To find out which version of Java is installed, open a command prompt and type: To find out which version of Java is installed, open a command prompt and type:
</p> </p>
<pre class="notranslate"> <pre>
java -version java -version
</pre> </pre>
<p> <p>
...@@ -138,7 +138,7 @@ If you get an error message, you may need to add the Java binary directory to th ...@@ -138,7 +138,7 @@ If you get an error message, you may need to add the Java binary directory to th
<p> <p>
You can only start one instance of the H2 Console, You can only start one instance of the H2 Console,
otherwise you will get the following error message: otherwise you will get the following error message:
<code>The Web server could not be started. Possible cause: another server is already running...</code>. "The Web server could not be started. Possible cause: another server is already running...".
It is possible to start multiple console applications on the same computer (using different ports), It is possible to start multiple console applications on the same computer (using different ports),
but this is usually not required as the console supports multiple concurrent connections. but this is usually not required as the console supports multiple concurrent connections.
</p> </p>
...@@ -146,8 +146,8 @@ but this is usually not required as the console supports multiple concurrent con ...@@ -146,8 +146,8 @@ but this is usually not required as the console supports multiple concurrent con
<h3>Using another Port</h3> <h3>Using another Port</h3>
<p> <p>
If the port is in use by another application, you may want to start the H2 Console on a different port. If the port is in use by another application, you may want to start the H2 Console on a different port.
This can be done by changing the port in the file <code class="notranslate">.h2.server.properties</code>. This file is stored This can be done by changing the port in the file <code>.h2.server.properties</code>. This file is stored
in the user directory (for Windows, this is usually in "Documents and Settings/&lt;username&gt;"). in the user directory (for Windows, this is usually in <code>Documents and Settings/&lt;username&gt;</code>).
The relevant entry is webPort. The relevant entry is webPort.
</p> </p>
...@@ -155,10 +155,10 @@ The relevant entry is webPort. ...@@ -155,10 +155,10 @@ The relevant entry is webPort.
<p> <p>
If the server started successfully, you can connect to it using a web browser. If the server started successfully, you can connect to it using a web browser.
JavaScript needs to be enabled. JavaScript needs to be enabled.
If you started the server on the same computer as the browser, open the URL <code class="notranslate">http://localhost:8082</code>. If you started the server on the same computer as the browser, open the URL <code>http://localhost:8082</code>.
If you want to connect to the application from another computer, you need to provide the IP address of the server, for example: If you want to connect to the application from another computer, you need to provide the IP address of the server, for example:
<code class="notranslate">http://192.168.0.2:8082</code>. <code>http://192.168.0.2:8082</code>.
If you enabled SSL on the server side, the URL needs to start with <code class="notranslate">https://</code>. If you enabled SSL on the server side, the URL needs to start with <code>https://</code>.
</p> </p>
<h3>Multiple Concurrent Sessions</h3> <h3>Multiple Concurrent Sessions</h3>
...@@ -186,14 +186,14 @@ by clicking on the message. ...@@ -186,14 +186,14 @@ by clicking on the message.
<h3>Adding Database Drivers</h3> <h3>Adding Database Drivers</h3>
<p> <p>
Additional database drivers can be registered by adding the Jar file location of the driver to the environment Additional database drivers can be registered by adding the Jar file location of the driver to the environment
variables <code class="notranslate">H2DRIVERS</code> or <code class="notranslate">CLASSPATH</code>. variables <code>H2DRIVERS</code> or <code>CLASSPATH</code>.
Example (Windows): to add the database driver library Example (Windows): to add the database driver library
<code class="notranslate">C:\Programs\hsqldb\lib\hsqldb.jar</code>, set the environment variable <code>C:\Programs\hsqldb\lib\hsqldb.jar</code>, set the environment variable
<code class="notranslate">H2DRIVERS</code> to <code>H2DRIVERS</code> to
<code class="notranslate">C:\Programs\hsqldb\lib\hsqldb.jar</code>. <code>C:\Programs\hsqldb\lib\hsqldb.jar</code>.
</p><p> </p><p>
Multiple drivers can be set; each entry needs to be separated with a <code class="notranslate">;</code> (Windows) Multiple drivers can be set; each entry needs to be separated with a <code>;</code> (Windows)
or <code class="notranslate">:</code> (other operating systems). or <code>:</code> (other operating systems).
Spaces in the path names are supported. The settings must not be quoted. Spaces in the path names are supported. The settings must not be quoted.
</p> </p>
...@@ -207,9 +207,9 @@ Type in a SQL command on the query panel and click 'Run'. The result of the comm ...@@ -207,9 +207,9 @@ Type in a SQL command on the query panel and click 'Run'. The result of the comm
<h3>Inserting Table Names or Column Names</h3> <h3>Inserting Table Names or Column Names</h3>
<p> <p>
The table name and column names can be inserted in the script by clicking them in the tree. The table name and column names can be inserted in the script by clicking them in the tree.
If you click on a table while the query is empty, then <code class="notranslate">SELECT * FROM ...</code> is added as well. If you click on a table while the query is empty, then <code>SELECT * FROM ...</code> is added as well.
While typing a query, the table that was used is automatically expanded in the tree. While typing a query, the table that was used is automatically expanded in the tree.
For example if you type <code class="notranslate">SELECT * FROM TEST T WHERE T.</code> then the table TEST is automatically expanded in the tree. For example if you type <code>SELECT * FROM TEST T WHERE T.</code> then the table TEST is automatically expanded in the tree.
</p> </p>
<h3>Disconnecting and Stopping the Application</h3> <h3>Disconnecting and Stopping the Application</h3>
...@@ -228,8 +228,8 @@ or close the console window. ...@@ -228,8 +228,8 @@ or close the console window.
<h2 id="console_settings">Settings of the H2 Console</h2> <h2 id="console_settings">Settings of the H2 Console</h2>
<p> <p>
The settings of the H2 Console are stored in a configuration file The settings of the H2 Console are stored in a configuration file
called <code class="notranslate">.h2.server.properties</code> in you user home directory. called <code>.h2.server.properties</code> in you user home directory.
For Windows installations, the user home directory is usually <code class="notranslate">C:\Documents and Settings\[username]</code>. For Windows installations, the user home directory is usually <code>C:\Documents and Settings\[username]</code>.
The configuration file contains the settings of the application and is automatically created when the H2 Console is first started. The configuration file contains the settings of the application and is automatically created when the H2 Console is first started.
</p> </p>
...@@ -239,7 +239,7 @@ The configuration file contains the settings of the application and is automatic ...@@ -239,7 +239,7 @@ The configuration file contains the settings of the application and is automatic
To connect to a database, a Java application first needs to load the database driver, To connect to a database, a Java application first needs to load the database driver,
and then get a connection. A simple way to do that is using the following code: and then get a connection. A simple way to do that is using the following code:
</p> </p>
<pre class="notranslate"> <pre>
import java.sql.*; import java.sql.*;
public class Test { public class Test {
public static void main(String[] a) public static void main(String[] a)
...@@ -253,12 +253,12 @@ public class Test { ...@@ -253,12 +253,12 @@ public class Test {
} }
</pre> </pre>
<p> <p>
This code first loads the driver (<code class="notranslate">Class.forName(...)</code>) This code first loads the driver (<code>Class.forName(...)</code>)
and then opens a connection (using <code class="notranslate">DriverManager.getConnection()</code>). and then opens a connection (using <code>DriverManager.getConnection()</code>).
The driver name is <code class="notranslate">"org.h2.Driver"</code>. The driver name is <code>"org.h2.Driver"</code>.
The database URL always needs to start with <code class="notranslate">jdbc:h2:</code> The database URL always needs to start with <code>jdbc:h2:</code>
to be recognized by this database. The second parameter in the <code class="notranslate">getConnection()</code> call to be recognized by this database. The second parameter in the <code>getConnection()</code> call
is the user name (<code class="notranslate">sa</code> for System Administrator in this example). The third parameter is the password. is the user name (<code>sa</code> for System Administrator in this example). The third parameter is the password.
In this database, user names are not case sensitive, but passwords are. In this database, user names are not case sensitive, but passwords are.
</p> </p>
...@@ -275,25 +275,24 @@ the administrator of this database. ...@@ -275,25 +275,24 @@ the administrator of this database.
<p> <p>
H2 currently supports three server: a web server (for the H2 Console), H2 currently supports three server: a web server (for the H2 Console),
a TCP server (for client/server connections) and an PG server (for PostgreSQL clients). a TCP server (for client/server connections) and an PG server (for PostgreSQL clients).
The servers can be started in different ways, one is using the server tool. The servers can be started in different ways, one is using the <code>Server</code> tool.
</p> </p>
<h3>Starting the Server Tool from Command Line</h3> <h3>Starting the Server Tool from Command Line</h3>
<p> <p>
To start the server tool from the command line with the default settings, run: To start the <code>Server</code> tool from the command line with the default settings, run:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Server java -cp h2*.jar org.h2.tools.Server
</pre> </pre>
<p> <p>
This will start the server tool with the default options. To get the list of options and default values, run: This will start the tool with the default options. To get the list of options and default values, run:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Server -? java -cp h2*.jar org.h2.tools.Server -?
</pre> </pre>
<p> <p>
There are options available to use other ports, and start or not start There are options available to use other ports, and start or not start parts.
parts. For details, see the API documentation of the server tool.
</p> </p>
<h3>Connecting to the TCP Server</h3> <h3>Connecting to the TCP Server</h3>
...@@ -301,8 +300,8 @@ parts. For details, see the API documentation of the server tool. ...@@ -301,8 +300,8 @@ parts. For details, see the API documentation of the server tool.
To remotely connect to a database using the TCP server, use the following driver and database URL: To remotely connect to a database using the TCP server, use the following driver and database URL:
</p> </p>
<ul> <ul>
<li>JDBC driver class: <code class="notranslate">org.h2.Driver</code> <li>JDBC driver class: <code>org.h2.Driver</code>
</li><li>Database URL: <code class="notranslate">jdbc:h2:tcp://localhost/~/test</code> </li><li>Database URL: <code>jdbc:h2:tcp://localhost/~/test</code>
</li></ul> </li></ul>
<p> <p>
For details about the database URL, see also in Features. For details about the database URL, see also in Features.
...@@ -312,7 +311,7 @@ For details about the database URL, see also in Features. ...@@ -312,7 +311,7 @@ For details about the database URL, see also in Features.
<p> <p>
Servers can also be started and stopped from within an application. Sample code: Servers can also be started and stopped from within an application. Sample code:
</p> </p>
<pre class="notranslate"> <pre>
import org.h2.tools.Server; import org.h2.tools.Server;
... ...
// start the TCP Server // start the TCP Server
...@@ -327,13 +326,13 @@ server.stop(); ...@@ -327,13 +326,13 @@ server.stop();
The TCP server can be stopped from another process. The TCP server can be stopped from another process.
To stop the server from the command line, run: To stop the server from the command line, run:
</p> </p>
<pre class="notranslate"> <pre>
java org.h2.tools.Server -tcpShutdown tcp://localhost:9092 java org.h2.tools.Server -tcpShutdown tcp://localhost:9092
</pre> </pre>
<p> <p>
To stop the server from a user application, use the following code: To stop the server from a user application, use the following code:
</p> </p>
<pre class="notranslate"> <pre>
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094"); org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094");
</pre> </pre>
<p> <p>
...@@ -342,7 +341,7 @@ If other server were started in the same process, they will continue to run. ...@@ -342,7 +341,7 @@ If other server were started in the same process, they will continue to run.
To avoid recovery when the databases are opened the next time, To avoid recovery when the databases are opened the next time,
all connections to the databases should be closed before calling this method. all connections to the databases should be closed before calling this method.
To stop a remote server, remote connections must be enabled on the server. To stop a remote server, remote connections must be enabled on the server.
Shutting down a TCP server can be protected using the option <code class="notranslate">-tcpPassword</code> Shutting down a TCP server can be protected using the option <code>-tcpPassword</code>
(the same password must be used to start and stop the TCP server). (the same password must be used to start and stop the TCP server).
</p> </p>
...@@ -353,35 +352,35 @@ This database supports Hibernate version 3.1 and newer. You can use the HSQLDB D ...@@ -353,35 +352,35 @@ This database supports Hibernate version 3.1 and newer. You can use the HSQLDB D
or the native H2 Dialect. Unfortunately the H2 Dialect included in Hibernate is buggy. A or the native H2 Dialect. Unfortunately the H2 Dialect included in Hibernate is buggy. A
<a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-3401">patch <a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-3401">patch
for Hibernate</a> has been submitted. The dialect for the newest version of Hibernate for Hibernate</a> has been submitted. The dialect for the newest version of Hibernate
is also available at <code class="notranslate">src/tools/org/hibernate/dialect/H2Dialect.java.txt</code>. is also available at <code>src/tools/org/hibernate/dialect/H2Dialect.java.txt</code>.
You can rename it to <code class="notranslate">H2Dialect.java</code> and include this as a patch in your application. You can rename it to <code>H2Dialect.java</code> and include this as a patch in your application.
</p> </p>
<br /> <br />
<h2 id="using_toplink">Using TopLink and Glassfish</h2> <h2 id="using_toplink">Using TopLink and Glassfish</h2>
<p> <p>
To use H2 with Glassfish (or Sun AS), set the Datasource Classname to To use H2 with Glassfish (or Sun AS), set the Datasource Classname to
<code class="notranslate">org.h2.jdbcx.JdbcDataSource</code>. You can set this in the GUI <code>org.h2.jdbcx.JdbcDataSource</code>. You can set this in the GUI
at Application Server - Resources - JDBC - Connection Pools, at Application Server - Resources - JDBC - Connection Pools,
or by editing the file <code class="notranslate">sun-resources.xml</code>: at element or by editing the file <code>sun-resources.xml</code>: at element
<code class="notranslate">jdbc-connection-pool</code>, set the attribute <code>jdbc-connection-pool</code>, set the attribute
<code class="notranslate">datasource-classname</code> to <code class="notranslate">org.h2.jdbcx.JdbcDataSource</code>. <code>datasource-classname</code> to <code>org.h2.jdbcx.JdbcDataSource</code>.
</p> </p>
<p> <p>
The H2 database is compatible with HSQLDB and PostgreSQL. The H2 database is compatible with HSQLDB and PostgreSQL.
To take advantage of H2 specific features, use the <code class="notranslate">H2Platform</code>. To take advantage of H2 specific features, use the <code>H2Platform</code>.
The source code of this platform is included in H2 at The source code of this platform is included in H2 at
<code class="notranslate">src/tools/oracle/toplink/essentials/platform/database/DatabasePlatform.java.txt</code>. <code>src/tools/oracle/toplink/essentials/platform/database/DatabasePlatform.java.txt</code>.
You will need to copy this file to your application, and rename it to .java. You will need to copy this file to your application, and rename it to .java.
To enable it, change the following setting in persistence.xml: To enable it, change the following setting in persistence.xml:
</p> </p>
<pre class="notranslate"> <pre>
&lt;property &lt;property
name="toplink.target-database" name="toplink.target-database"
value="oracle.toplink.essentials.platform.database.H2Platform"/> value="oracle.toplink.essentials.platform.database.H2Platform"/>
</pre> </pre>
<p> <p>
In old versions of Glassfish, the property name is <code class="notranslate">toplink.platform.class.name</code>. In old versions of Glassfish, the property name is <code>toplink.platform.class.name</code>.
</p> </p>
<br /> <br />
...@@ -402,8 +401,8 @@ same process. Most Servlet Containers (for example Tomcat) are just ...@@ -402,8 +401,8 @@ same process. Most Servlet Containers (for example Tomcat) are just
using one process, so this is not a problem (unless you run Tomcat in using one process, so this is not a problem (unless you run Tomcat in
clustered mode). Tomcat uses multiple threads and multiple clustered mode). Tomcat uses multiple threads and multiple
classloaders. If multiple applications access the same database at the classloaders. If multiple applications access the same database at the
same time, you need to put the database jar in the <code class="notranslate">shared/lib</code> or same time, you need to put the database jar in the <code>shared/lib</code> or
<code class="notranslate">server/lib</code> directory. It is a good idea to open the database when the <code>server/lib</code> directory. It is a good idea to open the database when the
web application starts, and close it when the web application stops. web application starts, and close it when the web application stops.
If using multiple applications, only one (any) of them needs to do If using multiple applications, only one (any) of them needs to do
that. In the application, an idea is to use one connection per that. In the application, an idea is to use one connection per
...@@ -420,32 +419,32 @@ The server mode is similar, but it allows you to run the server in another proce ...@@ -420,32 +419,32 @@ The server mode is similar, but it allows you to run the server in another proce
<h3>Using a Servlet Listener to Start and Stop a Database</h3> <h3>Using a Servlet Listener to Start and Stop a Database</h3>
<p> <p>
Add the h2*.jar file to your web application, and Add the h2*.jar file to your web application, and
add the following snippet to your web.xml file (between the add the following snippet to your web.xml file (between the
<code class="notranslate">context-param</code> and the <code class="notranslate">filter</code> section): <code>context-param</code> and the <code>filter</code> section):
</p> </p>
<pre class="notranslate"> <pre>
&lt;listener> &lt;listener>
&lt;listener-class>org.h2.server.web.DbStarter&lt;/listener-class> &lt;listener-class>org.h2.server.web.DbStarter&lt;/listener-class>
&lt;/listener> &lt;/listener>
</pre> </pre>
<p> <p>
For details on how to access the database, see the file <code class="notranslate">DbStarter.java</code>. For details on how to access the database, see the file <code>DbStarter.java</code>.
By default this tool opens an embedded connection By default this tool opens an embedded connection
using the database URL <code class="notranslate">jdbc:h2:~/test</code>, using the database URL <code>jdbc:h2:~/test</code>,
user name <code class="notranslate">sa</code>, and password <code class="notranslate">sa</code>. user name <code>sa</code>, and password <code>sa</code>.
If you want to use this connection within your servlet, you can access as follows: If you want to use this connection within your servlet, you can access as follows:
</p> </p>
<pre class="notranslate"> <pre>
Connection conn = getServletContext().getAttribute("connection"); Connection conn = getServletContext().getAttribute("connection");
</pre> </pre>
<p> <p>
<code class="notranslate">DbStarter</code> can also start the TCP server, however this is disabled by default. <code>DbStarter</code> can also start the TCP server, however this is disabled by default.
To enable it, use the parameter <code class="notranslate">db.tcpServer</code> in the file <code class="notranslate">web.xml</code>. To enable it, use the parameter <code>db.tcpServer</code> in the file <code>web.xml</code>.
Here is the complete list of options. Here is the complete list of options.
These options need to be placed between the <code class="notranslate">description</code> tag These options need to be placed between the <code>description</code> tag
and the <code class="notranslate">listener</code> / <code class="notranslate">filter</code> tags: and the <code>listener</code> / <code>filter</code> tags:
</p> </p>
<pre class="notranslate"> <pre>
&lt;context-param> &lt;context-param>
&lt;param-name>db.url&lt;/param-name> &lt;param-name>db.url&lt;/param-name>
&lt;param-value>jdbc:h2:~/test&lt;/param-value> &lt;param-value>jdbc:h2:~/test&lt;/param-value>
...@@ -465,16 +464,16 @@ and the <code class="notranslate">listener</code> / <code class="notranslate">fi ...@@ -465,16 +464,16 @@ and the <code class="notranslate">listener</code> / <code class="notranslate">fi
</pre> </pre>
<p> <p>
When the web application is stopped, the database connection will be closed automatically. When the web application is stopped, the database connection will be closed automatically.
If the TCP server is started within the <code class="notranslate">DbStarter</code>, it will also be stopped automatically. If the TCP server is started within the <code>DbStarter</code>, it will also be stopped automatically.
</p> </p>
<h3>Using the H2 Console Servlet</h3> <h3>Using the H2 Console Servlet</h3>
<p> <p>
The H2 Console is a standalone application and includes its own web server, but it can be The H2 Console is a standalone application and includes its own web server, but it can be
used as a servlet as well. To do that, include the the <code class="notranslate">h2*.jar</code> file in your application, and used as a servlet as well. To do that, include the the <code>h2*.jar</code> file in your application, and
add the following configuration to your <code class="notranslate">web.xml</code>: add the following configuration to your <code>web.xml</code>:
</p> </p>
<pre class="notranslate"> <pre>
&lt;servlet&gt; &lt;servlet&gt;
&lt;servlet-name&gt;H2Console&lt;/servlet-name&gt; &lt;servlet-name&gt;H2Console&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.h2.server.web.WebServlet&lt;/servlet-class&gt; &lt;servlet-class&gt;org.h2.server.web.WebServlet&lt;/servlet-class&gt;
...@@ -486,29 +485,29 @@ add the following configuration to your <code class="notranslate">web.xml</code> ...@@ -486,29 +485,29 @@ add the following configuration to your <code class="notranslate">web.xml</code>
&lt;/servlet-mapping&gt; &lt;/servlet-mapping&gt;
</pre> </pre>
<p> <p>
For details, see also <code class="notranslate">src/tools/WEB-INF/web.xml</code>. For details, see also <code>src/tools/WEB-INF/web.xml</code>.
</p> </p>
<p> <p>
To create a web application with just the H2 Console, run the following command: To create a web application with just the H2 Console, run the following command:
</p> </p>
<pre class="notranslate"> <pre>
build warConsole build warConsole
</pre> </pre>
<br /> <br />
<h2 id="csv">CSV (Comma Separated Values) Support</h2> <h2 id="csv">CSV (Comma Separated Values) Support</h2>
<p> <p>
The CSV file support can be used inside the database using the functions The CSV file support can be used inside the database using the functions
<code class="notranslate">CSVREAD</code> and <code class="notranslate">CSVWRITE</code>, <code>CSVREAD</code> and <code>CSVWRITE</code>,
or it can be used outside the database as a standalone tool. or it can be used outside the database as a standalone tool.
</p> </p>
<h3>Writing a CSV File from Within a Database</h3> <h3>Writing a CSV File from Within a Database</h3>
<p> <p>
The built-in function <code class="notranslate">CSVWRITE</code> can be used to create a CSV file from a query. The built-in function <code>CSVWRITE</code> can be used to create a CSV file from a query.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
CREATE TABLE TEST(ID INT, NAME VARCHAR); CREATE TABLE TEST(ID INT, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'); INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');
CALL CSVWRITE('test.csv', 'SELECT * FROM TEST'); CALL CSVWRITE('test.csv', 'SELECT * FROM TEST');
...@@ -516,18 +515,18 @@ CALL CSVWRITE('test.csv', 'SELECT * FROM TEST'); ...@@ -516,18 +515,18 @@ CALL CSVWRITE('test.csv', 'SELECT * FROM TEST');
<h3>Reading a CSV File from Within a Database</h3> <h3>Reading a CSV File from Within a Database</h3>
<p> <p>
A CSV file can be read using the function <code class="notranslate">CSVREAD</code>. Example: A CSV file can be read using the function <code>CSVREAD</code>. Example:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM CSVREAD('test.csv'); SELECT * FROM CSVREAD('test.csv');
</pre> </pre>
<h3>Writing a CSV File from a Java Application</h3> <h3>Writing a CSV File from a Java Application</h3>
<p> <p>
The CSV tool can be used in a Java application even when not using a database at all. The <code>Csv</code> tool can be used in a Java application even when not using a database at all.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
import java.sql.*; import java.sql.*;
import org.h2.tools.Csv; import org.h2.tools.Csv;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
...@@ -548,7 +547,7 @@ public class TestCsv { ...@@ -548,7 +547,7 @@ public class TestCsv {
It is possible to read a CSV file without opening a database. It is possible to read a CSV file without opening a database.
Example: Example:
</p> </p>
<pre class="notranslate"> <pre>
import java.sql.*; import java.sql.*;
import org.h2.tools.Csv; import org.h2.tools.Csv;
public class TestCsv { public class TestCsv {
...@@ -584,48 +583,48 @@ and then execute the SQL script using the new engine. ...@@ -584,48 +583,48 @@ and then execute the SQL script using the new engine.
There are different ways to backup a database. For example, it is possible to copy the database files. There are different ways to backup a database. For example, it is possible to copy the database files.
However, this is not recommended while the database is in use. Also, the database files are not human readable However, this is not recommended while the database is in use. Also, the database files are not human readable
and quite large. The recommended way to backup a database is to create a compressed SQL script file. and quite large. The recommended way to backup a database is to create a compressed SQL script file.
This can be done using the Script tool: This can be done using the <code>Script</code> tool:
</p> </p>
<pre class="notranslate"> <pre>
java org.h2.tools.Script -url jdbc:h2:~/test -user sa -script test.zip -options compression zip java org.h2.tools.Script -url jdbc:h2:~/test -user sa -script test.zip -options compression zip
</pre> </pre>
<p> <p>
It is also possible to use the SQL command <code class="notranslate">SCRIPT</code> to create the backup of the database. It is also possible to use the SQL command <code>SCRIPT</code> to create the backup of the database.
For more information about the options, see the SQL command <code class="notranslate">SCRIPT</code>. For more information about the options, see the SQL command <code>SCRIPT</code>.
The backup can be done remotely, however the file will be created on the server side. The backup can be done remotely, however the file will be created on the server side.
The built in FTP server could be used to retrieve the file from the server. The built in FTP server could be used to retrieve the file from the server.
</p> </p>
<h3>Restore from a Script</h3> <h3>Restore from a Script</h3>
<p> <p>
To restore a database from a SQL script file, you can use the RunScript tool: To restore a database from a SQL script file, you can use the <code>RunScript</code> tool:
</p> </p>
<pre class="notranslate"> <pre>
java org.h2.tools.RunScript -url jdbc:h2:~/test -user sa -script test.zip -options compression zip java org.h2.tools.RunScript -url jdbc:h2:~/test -user sa -script test.zip -options compression zip
</pre> </pre>
<p> <p>
For more information about the options, see the SQL command <code class="notranslate">RUNSCRIPT</code>. For more information about the options, see the SQL command <code>RUNSCRIPT</code>.
The restore can be done remotely, however the file needs to be on the server side. The restore can be done remotely, however the file needs to be on the server side.
The built in FTP server could be used to copy the file to the server. The built in FTP server could be used to copy the file to the server.
It is also possible to use the SQL command <code class="notranslate">RUNSCRIPT</code> to execute a SQL script. It is also possible to use the SQL command <code>RUNSCRIPT</code> to execute a SQL script.
SQL script files may contain references to other script files, in the form of SQL script files may contain references to other script files, in the form of
<code class="notranslate">RUNSCRIPT</code> commands. However, when using the server mode, the references script files <code>RUNSCRIPT</code> commands. However, when using the server mode, the references script files
need to be available on the server side. need to be available on the server side.
</p> </p>
<h3>Online Backup</h3> <h3>Online Backup</h3>
<p> <p>
The <code class="notranslate">BACKUP</code> SQL statement and the Backup tool both create a zip file The <code>BACKUP</code> SQL statement and the <code>Backup</code> tool both create a zip file
with all database files. However, the contents of this file are not human readable. with all database files. However, the contents of this file are not human readable.
Other than the SCRIPT statement, the <code class="notranslate">BACKUP</code> statement does not lock the Other than the SCRIPT statement, the <code>BACKUP</code> statement does not lock the
database objects, and therefore does not block other users. The resulting database objects, and therefore does not block other users. The resulting
backup is transactionally consistent: backup is transactionally consistent:
</p> </p>
<pre class="notranslate"> <pre>
BACKUP TO 'backup.zip' BACKUP TO 'backup.zip'
</pre> </pre>
<p> <p>
The Backup tool (org.h2.tools.Backup) can not be used to create a online backup; The <code>Backup</code> tool (<code>org.h2.tools.Backup</code>) can not be used to create a online backup;
the database must not be in use while running this program. the database must not be in use while running this program.
</p> </p>
<p> <p>
...@@ -640,24 +639,24 @@ be guaranteed that the data is copied in the right order. ...@@ -640,24 +639,24 @@ be guaranteed that the data is copied in the right order.
This database comes with a number of command line tools. To get more information about a tool, This database comes with a number of command line tools. To get more information about a tool,
start it with the parameter '-?', for example: start it with the parameter '-?', for example:
</p> </p>
<pre class="notranslate"> <pre>
java -cp h2*.jar org.h2.tools.Backup -? java -cp h2*.jar org.h2.tools.Backup -?
</pre> </pre>
<p> <p>
The command line tools are: The command line tools are:
</p> </p>
<ul><li><code class="notranslate">Backup</code> creates a backup of a database. <ul><li><code>Backup</code> creates a backup of a database.
</li><li><code class="notranslate">ChangeFileEncryption</code> allows changing the file encryption password or algorithm of a database. </li><li><code>ChangeFileEncryption</code> allows changing the file encryption password or algorithm of a database.
</li><li><code class="notranslate">Console</code> starts the browser based H2 Console. </li><li><code>Console</code> starts the browser based H2 Console.
</li><li><code class="notranslate">ConvertTraceFile</code> converts a .trace.db file to a Java application and SQL script. </li><li><code>ConvertTraceFile</code> converts a .trace.db file to a Java application and SQL script.
</li><li><code class="notranslate">CreateCluster</code> creates a cluster from a standalone database. </li><li><code>CreateCluster</code> creates a cluster from a standalone database.
</li><li><code class="notranslate">DeleteDbFiles</code> deletes all files belonging to a database. </li><li><code>DeleteDbFiles</code> deletes all files belonging to a database.
</li><li><code class="notranslate">Recover</code> helps recovering a corrupted database. </li><li><code>Recover</code> helps recovering a corrupted database.
</li><li><code class="notranslate">Restore</code> restores a backup of a database. </li><li><code>Restore</code> restores a backup of a database.
</li><li><code class="notranslate">RunScript</code> runs a SQL script against a database. </li><li><code>RunScript</code> runs a SQL script against a database.
</li><li><code class="notranslate">Script</code> allows converting a database to a SQL script for backup or migration. </li><li><code>Script</code> allows converting a database to a SQL script for backup or migration.
</li><li><code class="notranslate">Server</code> is used in the server mode to start a H2 server. </li><li><code>Server</code> is used in the server mode to start a H2 server.
</li><li><code class="notranslate">Shell</code> is a command line database tool. </li><li><code>Shell</code> is a command line database tool.
</li></ul> </li></ul>
<p> <p>
The tools can also be called from an application by calling the main or another public method. The tools can also be called from an application by calling the main or another public method.
...@@ -678,8 +677,8 @@ The steps to connect to a H2 database are: ...@@ -678,8 +677,8 @@ The steps to connect to a H2 database are:
</li><li>Click [OK] (as much as needed), stop OpenOffice (including the Quickstarter) </li><li>Click [OK] (as much as needed), stop OpenOffice (including the Quickstarter)
</li><li>Start OpenOffice Base </li><li>Start OpenOffice Base
</li><li>Connect to an existing database; select [JDBC]; [Next] </li><li>Connect to an existing database; select [JDBC]; [Next]
</li><li>Example datasource URL: <code class="notranslate">jdbc:h2:~/test</code> </li><li>Example datasource URL: <code>jdbc:h2:~/test</code>
</li><li>JDBC driver class: <code class="notranslate">org.h2.Driver</code> </li><li>JDBC driver class: <code>org.h2.Driver</code>
</li></ul> </li></ul>
<p> <p>
Now you can access the database stored in the current users home directory. Now you can access the database stored in the current users home directory.
...@@ -698,8 +697,8 @@ Now, when creating a new database using the "Database Wizard" : ...@@ -698,8 +697,8 @@ Now, when creating a new database using the "Database Wizard" :
</p> </p>
<ul><li>Click [File], [New], [Database]. <ul><li>Click [File], [New], [Database].
</li><li>Select [Connect to existing database] and the select [JDBC]. Click next. </li><li>Select [Connect to existing database] and the select [JDBC]. Click next.
</li><li>Example datasource URL: <code class="notranslate">jdbc:h2:~/test</code> </li><li>Example datasource URL: <code>jdbc:h2:~/test</code>
</li><li>JDBC driver class: <code class="notranslate">org.h2.Driver</code> </li><li>JDBC driver class: <code>org.h2.Driver</code>
</li></ul> </li></ul>
<p> <p>
Another solution to use H2 in NeoOffice is: Another solution to use H2 in NeoOffice is:
...@@ -717,11 +716,11 @@ See also <a href="http://wiki.services.openoffice.org/wiki/Extensions_developmen ...@@ -717,11 +716,11 @@ See also <a href="http://wiki.services.openoffice.org/wiki/Extensions_developmen
<p> <p>
When using Java Web Start / JNLP (Java Network Launch Protocol), permissions tags must be set in the .jnlp file, When using Java Web Start / JNLP (Java Network Launch Protocol), permissions tags must be set in the .jnlp file,
and the application .jar file must be signed. Otherwise, when trying to write to the file system, the following and the application .jar file must be signed. Otherwise, when trying to write to the file system, the following
exception will occur: <code class="notranslate">java.security.AccessControlException</code>: exception will occur: <code>java.security.AccessControlException</code>:
access denied (<code class="notranslate">java.io.FilePermission ... read</code>). access denied (<code>java.io.FilePermission ... read</code>).
Example permission tags: Example permission tags:
</p> </p>
<pre class="notranslate"> <pre>
&lt;security> &lt;security>
&lt;all-permissions/> &lt;all-permissions/>
&lt;/security> &lt;/security>
...@@ -737,9 +736,9 @@ A simple connection pool is included in H2. It is based on the ...@@ -737,9 +736,9 @@ A simple connection pool is included in H2. It is based on the
from Christian d'Heureuse. There are other, more complex, open source connection pools available, from Christian d'Heureuse. There are other, more complex, open source connection pools available,
for example the <a href="http://jakarta.apache.org/commons/dbcp/">Apache Commons DBCP</a>. for example the <a href="http://jakarta.apache.org/commons/dbcp/">Apache Commons DBCP</a>.
For H2, it is about twice as faster to get a connection from the built-in connection pool than to get For H2, it is about twice as faster to get a connection from the built-in connection pool than to get
one using <code class="notranslate">DriverManager.getConnection()</code>.The build-in connection pool is used as follows: one using <code>DriverManager.getConnection()</code>.The build-in connection pool is used as follows:
</p> </p>
<pre class="notranslate"> <pre>
import java.sql.*; import java.sql.*;
import org.h2.jdbcx.JdbcConnectionPool; import org.h2.jdbcx.JdbcConnectionPool;
public class Test { public class Test {
...@@ -768,7 +767,7 @@ tables in the database. ...@@ -768,7 +767,7 @@ tables in the database.
<p> <p>
To initialize, call: To initialize, call:
</p> </p>
<pre class="notranslate"> <pre>
CREATE ALIAS IF NOT EXISTS FT_INIT FOR "org.h2.fulltext.FullText.init"; CREATE ALIAS IF NOT EXISTS FT_INIT FOR "org.h2.fulltext.FullText.init";
CALL FT_INIT(); CALL FT_INIT();
</pre> </pre>
...@@ -776,7 +775,7 @@ CALL FT_INIT(); ...@@ -776,7 +775,7 @@ CALL FT_INIT();
You need to initialize it in each database where you want to use it. You need to initialize it in each database where you want to use it.
Afterwards, you can create a fulltext index for a table using: Afterwards, you can create a fulltext index for a table using:
</p> </p>
<pre class="notranslate"> <pre>
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR); CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello World'); INSERT INTO TEST VALUES(1, 'Hello World');
CALL FT_CREATE_INDEX('PUBLIC', 'TEST', NULL); CALL FT_CREATE_INDEX('PUBLIC', 'TEST', NULL);
...@@ -786,29 +785,29 @@ PUBLIC is the schema, TEST is the table name. The list of column names (column s ...@@ -786,29 +785,29 @@ PUBLIC is the schema, TEST is the table name. The list of column names (column s
in this case all columns are indexed. The index is updated in realtime. in this case all columns are indexed. The index is updated in realtime.
To search the index, use the following query: To search the index, use the following query:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM FT_SEARCH('Hello', 0, 0); SELECT * FROM FT_SEARCH('Hello', 0, 0);
</pre> </pre>
<p> <p>
This will produce a result set that contains the query needed to retrieve the data: This will produce a result set that contains the query needed to retrieve the data:
</p> </p>
<pre class="notranslate"> <pre>
QUERY: "PUBLIC"."TEST" WHERE "ID"=1 QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre> </pre>
<p> <p>
To get the raw data, use <code class="notranslate">FT_SEARCH_DATA('Hello', 0, 0);</code>. To get the raw data, use <code>FT_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code class="notranslate">SCHEMA</code> (the schema name), The result contains the columns <code>SCHEMA</code> (the schema name),
<code class="notranslate">TABLE</code> (the table name), <code>TABLE</code> (the table name),
<code class="notranslate">COLUMNS</code> (an array of column names), and <code>COLUMNS</code> (an array of column names), and
<code class="notranslate">KEYS</code> (an array of objects). <code>KEYS</code> (an array of objects).
To join a table, use a join as in: To join a table, use a join as in:
<code class="notranslate">SELECT T.* FROM FT_SEARCH_DATA('Hello', 0, 0) FT, TEST T <code>SELECT T.* FROM FT_SEARCH_DATA('Hello', 0, 0) FT, TEST T
WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code> WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code>
</p> </p>
<p> <p>
You can also call the index from within a Java application: You can also call the index from within a Java application:
</p> </p>
<pre class="notranslate"> <pre>
org.h2.fulltext.FullText.search(conn, text, limit, offset); org.h2.fulltext.FullText.search(conn, text, limit, offset);
org.h2.fulltext.FullText.searchData(conn, text, limit, offset); org.h2.fulltext.FullText.searchData(conn, text, limit, offset);
</pre> </pre>
...@@ -817,11 +816,11 @@ org.h2.fulltext.FullText.searchData(conn, text, limit, offset); ...@@ -817,11 +816,11 @@ org.h2.fulltext.FullText.searchData(conn, text, limit, offset);
<p> <p>
To use the Lucene full text search, you need the Lucene library in the classpath. To use the Lucene full text search, you need the Lucene library in the classpath.
How to do that depends on the application; if you use the H2 Console, you can add the Lucene How to do that depends on the application; if you use the H2 Console, you can add the Lucene
jar file to the environment variables <code class="notranslate">H2DRIVERS</code> or jar file to the environment variables <code>H2DRIVERS</code> or
<code class="notranslate">CLASSPATH</code>. <code>CLASSPATH</code>.
To initialize the Lucene fulltext search in a database, call: To initialize the Lucene fulltext search in a database, call:
</p> </p>
<pre class="notranslate"> <pre>
CREATE ALIAS IF NOT EXISTS FTL_INIT FOR "org.h2.fulltext.FullTextLucene.init"; CREATE ALIAS IF NOT EXISTS FTL_INIT FOR "org.h2.fulltext.FullTextLucene.init";
CALL FTL_INIT(); CALL FTL_INIT();
</pre> </pre>
...@@ -829,7 +828,7 @@ CALL FTL_INIT(); ...@@ -829,7 +828,7 @@ CALL FTL_INIT();
You need to initialize it in each database where you want to use it. You need to initialize it in each database where you want to use it.
Afterwards, you can create a full text index for a table using: Afterwards, you can create a full text index for a table using:
</p> </p>
<pre class="notranslate"> <pre>
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR); CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello World'); INSERT INTO TEST VALUES(1, 'Hello World');
CALL FTL_CREATE_INDEX('PUBLIC', 'TEST', NULL); CALL FTL_CREATE_INDEX('PUBLIC', 'TEST', NULL);
...@@ -839,28 +838,28 @@ PUBLIC is the schema, TEST is the table name. The list of column names (column s ...@@ -839,28 +838,28 @@ PUBLIC is the schema, TEST is the table name. The list of column names (column s
in this case all columns are indexed. The index is updated in realtime. To search the index, in this case all columns are indexed. The index is updated in realtime. To search the index,
use the following query: use the following query:
</p> </p>
<pre class="notranslate"> <pre>
SELECT * FROM FTL_SEARCH('Hello', 0, 0); SELECT * FROM FTL_SEARCH('Hello', 0, 0);
</pre> </pre>
<p> <p>
This will produce a result set that contains the query needed to retrieve the data: This will produce a result set that contains the query needed to retrieve the data:
</p> </p>
<pre class="notranslate"> <pre>
QUERY: "PUBLIC"."TEST" WHERE "ID"=1 QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre> </pre>
<p> <p>
To get the raw data, use <code class="notranslate">FTL_SEARCH_DATA('Hello', 0, 0);</code>. To get the raw data, use <code>FTL_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code class="notranslate">SCHEMA</code> (the schema name), The result contains the columns <code>SCHEMA</code> (the schema name),
<code class="notranslate">TABLE</code> (the table name), <code>TABLE</code> (the table name),
<code class="notranslate">COLUMNS</code> (an array of column names), <code>COLUMNS</code> (an array of column names),
and <code class="notranslate">KEYS</code> (an array of objects). To join a table, use a join as in: and <code>KEYS</code> (an array of objects). To join a table, use a join as in:
<code class="notranslate">SELECT T.* FROM FTL_SEARCH_DATA('Hello', 0, 0) FT, TEST T <code>SELECT T.* FROM FTL_SEARCH_DATA('Hello', 0, 0) FT, TEST T
WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code> WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code>
</p> </p>
<p> <p>
You can also call the index from within a Java application: You can also call the index from within a Java application:
</p> </p>
<pre class="notranslate"> <pre>
org.h2.fulltext.FullTextLucene.search(conn, text, limit, offset); org.h2.fulltext.FullTextLucene.search(conn, text, limit, offset);
org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset); org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset);
</pre> </pre>
...@@ -868,22 +867,22 @@ org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset); ...@@ -868,22 +867,22 @@ org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset);
<br /> <br />
<h2 id="user_defined_variables">User-Defined Variables</h2> <h2 id="user_defined_variables">User-Defined Variables</h2>
<p> <p>
This database supports user-defined variables. Variables start with <code class="notranslate">@</code> and can be used wherever This database supports user-defined variables. Variables start with <code>@</code> and can be used wherever
expressions or parameters are allowed. Variables are not persisted and session scoped, that means only visible expressions or parameters are allowed. Variables are not persisted and session scoped, that means only visible
from within the session in which they are defined. A value is usually assigned using the SET command: from within the session in which they are defined. A value is usually assigned using the SET command:
</p> </p>
<pre class="notranslate"> <pre>
SET @USER = 'Joe'; SET @USER = 'Joe';
</pre> </pre>
<p> <p>
The value can also be changed using the SET() method. This is useful in queries: The value can also be changed using the SET() method. This is useful in queries:
</p> </p>
<pre class="notranslate"> <pre>
SET @TOTAL = NULL; SET @TOTAL = NULL;
SELECT X, SET(@TOTAL, IFNULL(@TOTAL, 1.) * X) F FROM SYSTEM_RANGE(1, 50); SELECT X, SET(@TOTAL, IFNULL(@TOTAL, 1.) * X) F FROM SYSTEM_RANGE(1, 50);
</pre> </pre>
<p> <p>
Variables that are not set evaluate to <code class="notranslate">NULL</code>. Variables that are not set evaluate to <code>NULL</code>.
The data type of a user-defined variable is the data type The data type of a user-defined variable is the data type
of the value assigned to it, that means it is not necessary (or possible) to declare variable names before using them. of the value assigned to it, that means it is not necessary (or possible) to declare variable names before using them.
There are no restrictions on the assigned values; large objects (LOBs) are supported as well. There are no restrictions on the assigned values; large objects (LOBs) are supported as well.
...@@ -894,7 +893,7 @@ There are no restrictions on the assigned values; large objects (LOBs) are suppo ...@@ -894,7 +893,7 @@ There are no restrictions on the assigned values; large objects (LOBs) are suppo
<p> <p>
Date, time and timestamp values support ISO 8601 formatting, including time zone: Date, time and timestamp values support ISO 8601 formatting, including time zone:
</p> </p>
<pre class="notranslate"> <pre>
CALL TIMESTAMP '2008-01-01 12:00:00+01:00'; CALL TIMESTAMP '2008-01-01 12:00:00+01:00';
</pre> </pre>
<p> <p>
...@@ -902,10 +901,10 @@ If the time zone is not set, the value is parsed using the current time zone set ...@@ -902,10 +901,10 @@ If the time zone is not set, the value is parsed using the current time zone set
Date and time information is stored in H2 database files in GMT (Greenwich Mean Time). Date and time information is stored in H2 database files in GMT (Greenwich Mean Time).
If the database is opened using another system time zone, the date and time will change accordingly. If the database is opened using another system time zone, the date and time will change accordingly.
If you want to move a database from one time zone to the other and don't want this to happen, If you want to move a database from one time zone to the other and don't want this to happen,
you need to create a SQL script file using the <code class="notranslate">SCRIPT</code> command or you need to create a SQL script file using the <code>SCRIPT</code> command or
<code class="notranslate">Script</code> tool, and then load <code>Script</code> tool, and then load
the database using the <code class="notranslate">RUNSCRIPT</code> command the database using the <code>RUNSCRIPT</code> command
or the <code class="notranslate">RunScript</code> tool in the new time zone. or the <code>RunScript</code> tool in the new time zone.
</p> </p>
<br /> <br />
...@@ -913,7 +912,7 @@ or the <code class="notranslate">RunScript</code> tool in the new time zone. ...@@ -913,7 +912,7 @@ or the <code class="notranslate">RunScript</code> tool in the new time zone.
<p> <p>
Use the following configuration to start and stop the H2 TCP server using the Spring Framework: Use the following configuration to start and stop the H2 TCP server using the Spring Framework:
</p> </p>
<pre class="notranslate"> <pre>
&lt;bean id = "org.h2.tools.Server" &lt;bean id = "org.h2.tools.Server"
class="org.h2.tools.Server" class="org.h2.tools.Server"
factory-method="createTcpServer" factory-method="createTcpServer"
...@@ -923,7 +922,7 @@ Use the following configuration to start and stop the H2 TCP server using the Sp ...@@ -923,7 +922,7 @@ Use the following configuration to start and stop the H2 TCP server using the Sp
&lt;/bean&gt; &lt;/bean&gt;
</pre> </pre>
<p> <p>
The <code class="notranslate">destroy-method</code> will help prevent exceptions on hot-redeployment or when restarting the server. The <code>destroy-method</code> will help prevent exceptions on hot-redeployment or when restarting the server.
</p> </p>
<!-- [close] { --></div></td></tr></table><!-- } --><!-- analytics --></body></html> <!-- [close] { --></div></td></tr></table><!-- } --><!-- analytics --></body></html>
......
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.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -297,15 +297,7 @@ java org.h2.test.TestAll timer ...@@ -297,15 +297,7 @@ java org.h2.test.TestAll timer
/* /*
replace class="n" with class="notranslate" for website documentation: rolling review at advanced.html (alphabetically)
documentation: rolling review at tutorial.html (alphabetically)
<code class="notranslate"></code>
check no space http: or https:
check space' and 'space
check spaceNULL and NULLspace
tool...
mvcc merge problem mvcc merge problem
......
...@@ -148,6 +148,8 @@ public class WebSite { ...@@ -148,6 +148,8 @@ public class WebSite {
if (web) { if (web) {
page = StringUtils.replaceAll(page, TRANSLATE_START, ""); page = StringUtils.replaceAll(page, TRANSLATE_START, "");
page = StringUtils.replaceAll(page, TRANSLATE_END, ""); page = StringUtils.replaceAll(page, TRANSLATE_END, "");
page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">");
page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">");
} }
bytes = page.getBytes("UTF-8"); bytes = page.getBytes("UTF-8");
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论