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

Documentation: improved website translation

上级 a08877c0
......@@ -7,7 +7,7 @@ Initial Developer: H2 Group
-->
<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>
Advanced Topics
Advanced
</title><link rel="stylesheet" type="text/css" href="stylesheet.css" />
<!-- [search] { -->
<script type="text/javascript" src="navigation.js"></script>
......@@ -15,7 +15,7 @@ Advanced Topics
<table class="content"><tr class="content"><td class="content"><div class="contentDiv">
<!-- } -->
<h1>Advanced Topics</h1>
<h1>Advanced</h1>
<a href="#result_sets">
Result Sets</a><br />
<a href="#large_objects">
......@@ -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.
If only the first few rows are interesting for the application, then the
result set size should be limited to improve the performance.
This can be done using <code class="notranslate">LIMIT</code> in a query
(example: <code class="notranslate">SELECT * FROM TEST LIMIT 100</code>),
or by using Statement.setMaxRows(max).
This can be done using <code>LIMIT</code> in a query
(example: <code>SELECT * FROM TEST LIMIT 100</code>),
or by using <code>Statement.setMaxRows(max)</code>.
</p>
<h3>Large Result Sets and External Sorting</h3>
<p>
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>.
If <code class="notranslate">ORDER BY</code> is used, the sorting is done using an
<code>SET MAX_MEMORY_ROWS</code>.
If <code>ORDER BY</code> is used, the sorting is done using an
external sort algorithm.
In this case, each block of rows is sorted using quick sort, then written to disk;
when reading the data, the blocks are merged together.
......@@ -135,16 +135,16 @@ then compressing can save a lot of disk space (sometimes more than 50%), and rea
<p>
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
<code class="notranslate">CREATE LINKED TABLE</code> statement:
<code>CREATE LINKED TABLE</code> statement:
</p>
<pre class="notranslate">
<pre>
CREATE LINKED TABLE LINK('org.postgresql.Driver', 'jdbc:postgresql:test', 'sa', 'sa', 'TEST');
</pre>
<p>
You can then access the table in the usual way.
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>,
then the following query is run against the PostgreSQL database: <code class="notranslate">SELECT * FROM TEST WHERE ID=?</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>SELECT * FROM TEST WHERE ID=?</code>.
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.
</p>
......@@ -153,10 +153,10 @@ To view the statements that are executed against the target table, set the trace
</p>
<p>
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>
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.
</p>
......@@ -175,16 +175,16 @@ This database supports the following transaction isolation levels:
This is the default level.
Read locks are released immediately.
Higher concurrency is possible when using this level.<br />
To enable, execute the SQL statement <code class="notranslate">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>
To enable, execute the SQL statement <code>SET LOCK_MODE 3</code><br />
or append <code>;LOCK_MODE=3</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=3</code>
</li><li>
<b>Serializable</b><br />
To enable, execute the SQL statement <code class="notranslate">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>
To enable, execute the SQL statement <code>SET LOCK_MODE 1</code><br />
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 />
This level means that transaction isolation is disabled.<br />
To enable, execute the SQL statement <code class="notranslate">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>
To enable, execute the SQL statement <code>SET LOCK_MODE 0</code><br />
or append <code>;LOCK_MODE=0</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=0</code>
</li>
</ul>
<p>
......@@ -238,7 +238,7 @@ for each connection.
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
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
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
......@@ -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.
</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>
<pre class="notranslate">
<pre>
jdbc:h2:~/test;MVCC=TRUE
</pre>
<p>
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
<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 setting <code class="notranslate">MAX_MEMORY_UNDO</code> has no effect).
(the setting <code>MAX_MEMORY_UNDO</code> has no effect).
</p>
<br />
......@@ -278,7 +278,7 @@ To initialize the cluster, use the following steps:
</p>
<ul>
<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.
Afterwards, you have two databases containing the same data.
</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
databases will be on different servers.
</p>
<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.
</li><li>Start a TCP server pointing to the first directory.
You can do this using the command line:
<pre class="notranslate">
<pre>
java org.h2.tools.Server
-tcp -tcpPort 9101
-baseDir server1
......@@ -304,15 +304,15 @@ java org.h2.tools.Server
</li><li>Start a second TCP server pointing to the second directory.
This will simulate a server running on a second (redundant) computer.
You can do this using the command line:
<pre class="notranslate">
<pre>
java org.h2.tools.Server
-tcp -tcpPort 9102
-baseDir server2
</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.
Run the tool on the command line:
<pre class="notranslate">
<pre>
java org.h2.tools.CreateCluster
-urlSource jdbc:h2:tcp://localhost:9101/~/test
-urlTarget jdbc:h2:tcp://localhost:9102/~/test
......@@ -321,13 +321,13 @@ java org.h2.tools.CreateCluster
</pre>
</li><li>You can now connect to the databases using
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),
you will notice that the other machine continues to work,
and therefore the database is still accessible.
</li><li>To restore the cluster, you first need to delete the
database that failed, then restart the server that was stopped,
and re-run the <code class="notranslate">CreateCluster</code> tool.
and re-run the <code>CreateCluster</code> tool.
</li></ul>
<h3>Clustering Algorithm and Limitations</h3>
......@@ -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
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
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].
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.
</p>
......@@ -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><li>A transaction is started, for example by inserting a row
</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>If a problem occurs before the transaction was successfully committed or rolled back
(for example because a network problem occurred), the transaction is in the state 'in-doubt'
</li><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
<code class="notranslate">COMMIT TRANSACTION transactionName</code> or
<code class="notranslate">ROLLBACK TRANSACTION transactionName</code>
<code>COMMIT TRANSACTION transactionName</code> or
<code>ROLLBACK TRANSACTION transactionName</code>
</li><li>The database needs to be closed and re-opened to apply the changes
</li></ul>
......@@ -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),
unless they are quoted (surrounded with double quotes). The list is currently:
</p><p>
<code class="notranslate">
<code>
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,
ON, ORDER, PRIMARY, ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TRUE, UNION, WHERE
</code>
</p><p>
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>
<br />
......@@ -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>
is included in the installation. Batch files are provided to install, start, stop and uninstall the
H2 Database Engine Service. This service contains the TCP Server and the H2 Console web application.
The batch files are located in the directory <code class="notranslate">h2/service</code>.
The batch files are located in the directory <code>h2/service</code>.
</p>
<h3>Install the Service</h3>
<p>
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.
</p>
<h3>Start the Service</h3>
<p>
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.
</p>
<h3>Connect to the H2 Console</h3>
<p>
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.
</p>
<h3>Stop the Service</h3>
<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.
</p>
<h3>Uninstall the Service</h3>
<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.
</p>
......@@ -456,7 +456,7 @@ as experimental. It should not be used for production applications.
</p>
<p>
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.
See also:
<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
<p>
After installing the ODBC driver, start the H2 Server using the command line:
</p>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Server
</pre>
<p>
......@@ -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.
Use -baseDir to save databases in another directory, for example the user home directory:
</p>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Server -baseDir ~
</pre>
<p>
The PG server can be started and stopped from within a Java application as follows:
</p>
<pre class="notranslate">
<pre>
Server server = Server.createPgServer("-baseDir", "~");
server.start();
...
......@@ -496,13 +496,13 @@ server.stop();
</pre>
<p>
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>
<h3>ODBC Configuration</h3>
<p>
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'.
You will be able to change the connection properties:
</p>
......@@ -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>Copy the h2*.jar file to ikvm/bin
</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:
<code class="notranslate">ikvmc -target:winexe h2*.jar</code>.
<code>ikvmc -target:winexe h2*.jar</code>.
You may ignore the warnings.
</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>
<p>
If you want your C# application use H2, you need to add the h2.dll and the
IKVM.OpenJDK.ClassLibrary.dll to your C# solution. Here some sample code:
</p>
<pre class="notranslate">
<pre>
using System;
using java.sql;
......@@ -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.
A durability test was run against H2, HSQLDB, PostgreSQL, and Derby.
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>
<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.
Making sure that committed transactions are not lost is more complicated than it seems first.
To guarantee complete durability, a database must ensure that the log record is on the hard drive
before the commit call returns. To do that, databases use different methods. One
is to use the 'synchronous write' file access mode. In Java, RandomAccessFile
supports the modes <code class="notranslate">"rws"</code> and <code class="notranslate">"rwd"</code>:
is to use the 'synchronous write' file access mode. In Java, <code>RandomAccessFile</code>
supports the modes <code>"rws"</code> and <code>"rwd"</code>:
</p>
<ul>
<li><code class="notranslate">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><code>rwd</code>: every update to the file's content is written synchronously to the underlying storage device.
</li><li><code>rws</code>: in addition to <code>rwd</code>, every update to the metadata is written synchronously.</li>
</ul>
<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.
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.
......@@ -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:
</p>
<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.
Sync is supposed to return after all in-memory modified copies of buffers associated with this FileDescriptor
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.
</li></ul>
<p>
By default, MySQL calls fsync for each commit. When using one of those methods, only around 60 write operations
per second can be achieved, which is consistent with the RPM rate of the hard drive used.
Unfortunately, even when calling <code class="notranslate">FileDescriptor.sync()</code> or
<code class="notranslate">FileChannel.force()</code>,
Unfortunately, even when calling <code>FileDescriptor.sync()</code> or
<code>FileChannel.force()</code>,
data is not always persisted to the hard drive, because most hard drives do not obey
fsync(): see
<a href="http://hardware.slashdot.org/article.pl?sid=05/05/13/0529252">Your Hard Drive Lies to You</a>.
......@@ -706,8 +706,8 @@ Because of those reasons, the default behavior of H2 is to delay writing committ
</p>
<p>
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
<code class="notranslate">CHECKPOINT SYNC</code>.
To change the behavior, use <code>SET WRITE_DELAY</code> and
<code>CHECKPOINT SYNC</code>.
Most other databases support commit delay as well.
In the performance comparison, commit delay was used for all databases that support it.
</p>
......@@ -715,7 +715,7 @@ In the performance comparison, commit delay was used for all databases that supp
<h3>Running the Durability Test</h3>
<p>
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.
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.
......@@ -731,24 +731,24 @@ consult the source code of the listener and test application.
<br />
<h2 id="using_recover_tool">Using the Recover Tool</h2>
<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).
To run the tool, type on the command line:
</p>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Recover
</pre>
<p>
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
the schema of the database. This file can be executed using the RunScript tool or a
<code class="notranslate">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
the schema of the database. This file can be executed using the <code>RunScript</code> tool or a
<code>RUNSCRIPT FROM</code> SQL statement. The script includes at least one
<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
against a database that was created with a user name that is not in the script.
</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
applied in the database.
</p>
......@@ -776,7 +776,7 @@ The default method for database file locking is the 'File Method'. The algorithm
</p>
<ul>
<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
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
......@@ -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>
<p>
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:
</p>
<ul>
......@@ -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.
Some applications build SQL statements with embedded user input such as:
</p>
<pre class="notranslate">
<pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD='"+pwd+"'";
ResultSet rs = conn.createStatement().executeQuery(sql);
</pre>
<p>
If this mechanism is used anywhere in the application, and user input is not correctly filtered or encoded,
it is possible for a user to inject SQL functionality or statements by using specially built input
such as (in this example) this password: <code class="notranslate">' OR ''='</code>.
such as (in this example) this password: <code>' OR ''='</code>.
In this case the statement becomes:
</p>
<pre class="notranslate">
<pre>
SELECT * FROM USERS WHERE PASSWORD='' OR ''='';
</pre>
<p>
......@@ -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.
A simple solution for the problem above is to use a prepared statement:
</p>
<pre class="notranslate">
<pre>
String sql = "SELECT * FROM USERS WHERE PASSWORD=?";
PreparedStatement prep = conn.prepareStatement(sql);
prep.setString(1, pwd);
......@@ -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 do this, execute the statement:
</p>
<pre class="notranslate">
<pre>
SET ALLOW_LITERALS NONE;
</pre>
<p>
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>
or <code class="notranslate">WHERE CustomerId=10</code> will fail.
That means, SQL statement of the form <code>WHERE NAME='abc'</code>
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
SQL statements dynamically, and use the Statement API, as long as the SQL statements
do not include literals.
There is also a second mode where number literals are allowed:
<code class="notranslate">SET ALLOW_LITERALS NUMBERS</code>.
To allow all literals, execute <code class="notranslate">SET ALLOW_LITERALS ALL</code>
<code>SET ALLOW_LITERALS NUMBERS</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.
</p>
<h3>Using Constants</h3>
<p>
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
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:
</p>
<pre class="notranslate">
<pre>
CREATE SCHEMA CONST AUTHORIZATION SA;
CREATE CONSTANT CONST.ACTIVE VALUE 'Active';
CREATE CONSTANT CONST.INACTIVE VALUE 'Inactive';
......@@ -916,9 +916,9 @@ time, the source code is easier to understand and change.
<h3>Using the ZERO() Function</h3>
<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>
<pre class="notranslate">
<pre>
SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO();
</pre>
......@@ -927,9 +927,9 @@ SELECT * FROM USERS WHERE LENGTH(PASSWORD)=ZERO();
<p>
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
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
<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,
ensure the existing accessible databases are protected using a strong password.
</p>
......@@ -939,9 +939,9 @@ ensure the existing accessible databases are protected using a strong password.
<p>
By default there is no restriction on loading classes and executing Java code for admins.
That means an admin may call system functions such as
<code class="notranslate">System.setProperty</code> by executing:
<code>System.setProperty</code> by executing:
</p>
<pre class="notranslate">
<pre>
CREATE ALIAS SET_PROPERTY FOR "java.lang.System.setProperty";
CALL SET_PROPERTY('abc', '1');
CREATE ALIAS GET_PROPERTY FOR "java.lang.System.getProperty";
......@@ -950,11 +950,11 @@ CALL GET_PROPERTY('abc');
<p>
To restrict users (including admins) from loading classes and executing code,
the list of allowed classes can be set in the system property
<code class="notranslate">h2.allowedClasses</code>
<code>h2.allowedClasses</code>
in the form of a comma separated list of classes or patterns (items ending with '*').
By default all classes are allowed. Example:
</p>
<pre class="notranslate">
<pre>
java -Dh2.allowedClasses=java.lang.Math,com.acme.*
</pre>
<p>
......@@ -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>
<p>
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>
and <code class="notranslate">h2.delayWrongPasswordMax</code> to change the minimum (the default is 250 milliseconds)
login gets double as long. Use the system properties <code>h2.delayWrongPasswordMin</code>
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
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)
......@@ -1069,7 +1069,7 @@ if the user name was wrong or the password.
<h3>HTTPS Connections</h3>
<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
custom certificates are supported as well.
</p>
......@@ -1078,18 +1078,18 @@ custom certificates are supported as well.
<h2 id="ssl_tls_connections">SSL/TLS Connections</h2>
<p>
Remote SSL/TLS connections are supported using the Java Secure Socket Extension
(<code class="notranslate">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>.
(<code>SSLServerSocket, SSLSocket</code>). By default, anonymous SSL is enabled.
The default cipher suite is <code>SSL_DH_anon_WITH_RC4_128_MD5</code>.
</p>
<p>
To use your own keystore, set the system properties <code class="notranslate">javax.net.ssl.keyStore</code> and
<code class="notranslate">javax.net.ssl.keyStorePassword</code> before starting the H2 server and client.
To use your own keystore, set the system properties <code>javax.net.ssl.keyStore</code> and
<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">
Customizing the Default Key and Trust Stores, Store Types, and Store Passwords</a>
for more information.
</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>
<br />
......@@ -1102,11 +1102,11 @@ using the probability theory. See also 'Birthday Paradox'.
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).
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
after generating a number of values:
</p>
<pre class="notranslate">
<pre>
public class Test {
public static void main(String[] args) throws Exception {
double x = Math.pow(2, 122);
......@@ -1123,11 +1123,12 @@ public class Test {
<p>
Some values are:
</p>
<pre>
2^36=68'719'476'736 probability: 0.000'000'000'000'000'4
2^41=2'199'023'255'552 probability: 0.000'000'000'000'4
2^46=70'368'744'177'664 probability: 0.000'000'000'4
</pre>
<table>
<tr><th>Number of UUIs</th><th>Probability of Duplicates</th></tr>
<tr><td>2^36=68'719'476'736</td><td>0.000'000'000'000'000'4</td></tr>
<tr><td>2^41=2'199'023'255'552</td><td>0.000'000'000'000'4</td></tr>
<tr><td>2^46=70'368'744'177'664</td><td>0.000'000'000'4</td></tr>
</table>
<p>
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,
......@@ -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>
<p>
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.
Example:
</p>
<pre class="notranslate">
<pre>
java -Dh2.serverCachedObjects=256 org.h2.tools.Server
</pre>
<p>
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>
For a complete list of settings, see
......@@ -1159,7 +1160,7 @@ For a complete list of settings, see
<p>
Usually server sockets accept connections on any/all local addresses.
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.
IPv4 and IPv6 address formats are supported.
</p>
......@@ -1170,20 +1171,20 @@ IPv4 and IPv6 address formats are supported.
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:
</p>
<ul><li><code class="notranslate">zip:</code> read-only zip-file based file system. Format: <code class="notranslate">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 class="notranslate">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 class="notranslate">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).
<ul><li><code>zip:</code> read-only zip-file based file system. Format: <code>zip:/zipFileName!/fileName</code>.
</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>nioMapped:</code> file system that uses memory mapped files (faster in some operating systems).
</li><li><code>split:</code> file system that splits files in 1 GB files (stackable with other file systems).
</li><li><code>memFS:</code> in-memory file system (experimental; used for testing).
</li><li><code>memLZF:</code> compressing in-memory file system (experimental; used for testing).
</li></ul>
<p>
As an example, to use the the <code class="notranslate">nio</code> file system, use the following database URL:
<code class="notranslate">jdbc:h2:nio:~/test</code>.
As an example, to use the the <code>nio</code> file system, use the following database URL:
<code>jdbc:h2:nio:~/test</code>.
</p>
<p>
To register a new file system, extend the classes <code class="notranslate">org.h2.store.fs.FileSystem, FileObject</code>,
and call the method <code class="notranslate">FileSystem.register</code> before using it.
To register a new file system, extend the classes <code>org.h2.store.fs.FileSystem, FileObject</code>,
and call the method <code>FileSystem.register</code> before using it.
</p>
<br />
......@@ -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>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
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:
<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>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 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.
Statements of the following form will result in a stack overflow exception:
<pre class="notranslate">
<pre>
SELECT * FROM DUAL WHERE X = 1
OR X = 2 OR X = 2 OR X = 2 OR X = 2 OR X = 2
-- repeat previous line 500 times --
......
......@@ -67,20 +67,20 @@ Newer version or compatible software works too.
<h2 id="building">Building the Software</h2>
<p>
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
the environment variable <code class="notranslate">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:
Ensure that Java binary directory is included in the <code>PATH</code> environment variable, and that
the environment variable <code>JAVA_HOME</code> points to your Java installation.
On the command line, go to the directory <code>h2</code> and execute the following command:
</p>
<pre class="notranslate">
<pre>
build -?
</pre>
<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>
You will get a list of targets. If you want to build the jar file, execute (Windows):
</p>
<pre class="notranslate">
<pre>
build jar
</pre>
......@@ -89,7 +89,7 @@ build jar
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:
</p>
<pre class="notranslate">
<pre>
build switchSource
</pre>
......@@ -98,20 +98,20 @@ build switchSource
<p>
The build system can generate smaller jar files as well. The following targets are currently supported:
</p>
<ul><li><code class="notranslate">jarClient</code>
creates the file <code class="notranslate">h2client.jar</code>. This only contains the JDBC client.
</li><li><code class="notranslate">jarSmall</code>
creates the file <code class="notranslate">h2small.jar</code>.
<ul><li><code>jarClient</code>
creates the file <code>h2client.jar</code>. This only contains the JDBC client.
</li><li><code>jarSmall</code>
creates the file <code>h2small.jar</code>.
This only contains the embedded database. Debug information is disabled.
</li><li><code class="notranslate">jarJaqu</code>
creates the file <code class="notranslate">h2jaqu.jar</code>.
</li><li><code>jarJaqu</code>
creates the file <code>h2jaqu.jar</code>.
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>
<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>
<pre class="notranslate">
<pre>
build jarClient
</pre>
......@@ -122,7 +122,7 @@ build jarClient
You can include the database in your Maven 2 project as a dependency.
Example:
</p>
<pre class="notranslate">
<pre>
&lt;dependency&gt;
&lt;groupId&gt;com.h2database&lt;/groupId&gt;
&lt;artifactId&gt;h2&lt;/artifactId&gt;
......@@ -139,13 +139,13 @@ they are available there.
<p>
To build a 'snapshot' H2 jar file and upload it the to the local Maven 2 repository, execute the following command:
</p>
<pre class="notranslate">
<pre>
build mavenInstallLocal
</pre>
<p>
Afterwards, you can include the database in your Maven 2 project as a dependency:
</p>
<pre class="notranslate">
<pre>
&lt;dependency&gt;
&lt;groupId&gt;com.h2database&lt;/groupId&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
The translation of this software is split into the following parts:
</p>
<ul>
<li>H2 Console: <code class="notranslate">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>Web site: <code class="notranslate">src/docsrc/text/_docs_*.utf8.txt</code>
<li>H2 Console: <code>src/main/org/h2/server/web/res/_text_*.properties</code>
</li><li>Error messages: <code>src/main/org/h2/res/_messages_*.properties</code>
</li><li>Web site: <code>src/docsrc/text/_docs_*.utf8.txt</code>
</li></ul>
<p>
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),
as well as the HTML entities (<code class="notranslate">&amp;#..;</code>)
is automated by running the tool <code class="notranslate">PropertiesToUTF8</code>.
The conversion between UTF-8 and Java encoding (using the <code>\u</code> syntax),
as well as the HTML entities (<code>&amp;#..;</code>)
is automated by running the tool <code>PropertiesToUTF8</code>.
The web site translation is automated as well,
using <code class="notranslate">build docs</code>.
using <code>build docs</code>.
</p>
<br />
......@@ -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).
</li><li>Follow the coding style used in the project, and use Checkstyle (see above) to verify.
For example, do not use tabs (use spaces instead).
The checkstyle configuration is in <code 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.
For Java level tests, see <code class="notranslate">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
<code class="notranslate">testSimple.in.txt</code>.
For Java level tests, see <code>src/test/org/h2/test/TestAll.java</code>.
For SQL level tests, see <code>src/test/org/h2/test/test.in.txt</code> or
<code>testSimple.in.txt</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).
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
<code class="notranslate">build test</code>.
</li><li>Provide end user documentation if required (<code class="notranslate">src/docsrc/html/*</code>).
</li><li>Document grammar changes in <code class="notranslate">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>Verify the spelling using <code class="notranslate">build spellcheck</code>. If required
add the new words to <code class="notranslate">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>Verify the formatting using <code class="notranslate">build docs</code> and
<code class="notranslate">build javadoc</code>.
</li><li>Submit patches as <code class="notranslate">.patch</code> files (compressed if big).
<code>build test</code>.
</li><li>Provide end user documentation if required (<code>src/docsrc/html/*</code>).
</li><li>Document grammar changes in <code>src/main/org/h2/res/help.csv</code>
</li><li>Provide a change log entry (<code>src/docsrc/html/changelog.html</code>).
</li><li>Verify the spelling using <code>build spellcheck</code>. If required
add the new words to <code>src/tools/org/h2/build/doc/dictionary.txt</code>.
</li><li>Run the <code>src/installer/buildRelease</code> to find and fix formatting errors.
</li><li>Verify the formatting using <code>build docs</code> and
<code>build javadoc</code>.
</li><li>Submit patches as <code>.patch</code> files (compressed if big).
To create a patch using Eclipse, use Team / Create Patch.
</li></ul>
<p>
......@@ -218,7 +218,7 @@ Eclipse Public License, version 1.0 (http://h2database.com/html/license.html)."
<p>
This build process is automated and runs regularly.
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:
</p>
<ul><li><a href="http://h2database.com/html/testOutput.html">Test Output</a>
......
......@@ -25,7 +25,7 @@ Data Types
<c:forEach var="item" items="dataTypes">
<br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate">
<pre>
${item.syntax}
</pre>
<p>${item.text}</p>
......
......@@ -46,21 +46,21 @@ Frequently Asked Questions
Usually, bugs get fixes as they are found. There is a release every few weeks.
Here is the list of known and confirmed issues:
</p>
<ul><li>Tomcat and Glassfish 3 set most static fields (final or non-final) to null when
unloading a web application. This can cause a <code class="notranslate">NullPointerException</code> in H2 versions
<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>NullPointerException</code> in H2 versions
1.1.107 and older, and may still not work in newer versions. Please report it if you
run into this issue. In Tomcat >= 6.0 this behavior can be disabled by setting the
system property <code 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
put the h2.jar file in a shared <code class="notranslate">lib</code> directory
(<code class="notranslate">common/lib</code>).
put the h2.jar file in a shared <code>lib</code> directory
(<code>common/lib</code>).
</li><li>Some problems have been found with right outer join. Internally, it is converted
to left outer join, which does not always produce the same results as other databases
when used in combination with other joins.
</li><li>When using Install4j before 4.1.4 on Linux and enabling 'pack200',
the <code class="notranslate">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>
next to the <code class="notranslate">h2*.jar</code> file.
</li><li>When using Install4j before 4.1.4 on Linux and enabling <code>pack200</code>,
the <code>h2*.jar</code> becomes corrupted by the install process, causing application failure.
A workaround is to add an empty file <code>h2*.jar.nopack</code>
next to the <code>h2*.jar</code> file.
This problem is solved in Install4j 4.1.4.
</li></ul>
......@@ -74,15 +74,15 @@ See also under license.
<br />
<h3 id="query_slow">My Query is Slow</h3>
<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:
</p>
<ul>
<li>Run <code class="notranslate">ANALYZE</code> (see documentation for details).
</li><li>Run the query with <code class="notranslate">EXPLAIN</code> and check if indexes are used
<li>Run <code>ANALYZE</code> (see documentation for details).
</li><li>Run the query with <code>EXPLAIN</code> and check if indexes are used
(see documentation for details).
</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>
</ul>
......@@ -96,11 +96,11 @@ By default, a new database is automatically created if it does not yet exist.
<br />
<h3 id="connect">How to Connect to a Database?</h3>
<p>
The database driver is <code class="notranslate">org.h2.Driver</code>,
and the database URL starts with <code class="notranslate">jdbc:h2:</code>.
The database driver is <code>org.h2.Driver</code>,
and the database URL starts with <code>jdbc:h2:</code>.
To connect to a database using JDBC, use the following code:
</p>
<pre class="notranslate">
<pre>
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
</pre>
......@@ -108,19 +108,19 @@ Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
<br />
<h3 id="database_files">Where are the Database Files Stored?</h3>
<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.
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 current working directory). When using the H2 Console application from the start menu,
this is "&lt;Installation Directory&gt;/bin".
The base directory can be set in the database URL. A fixed or relative path can be used. When using the URL
<code class="notranslate">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>jdbc:h2:file:data/sample</code>, the database is stored in the directory
<code>data</code> (relative to the current working directory).
The directory is created automatically if it does not yet exist. It is also possible to use the
fully qualified directory name (and for Windows, drive name).
Example: <code class="notranslate">jdbc:h2:file:C:/data/test</code>
Example: <code>jdbc:h2:file:C:/data/test</code>
</p>
<br />
......@@ -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
opened because the index file is corrupt. In that case, the index file can be deleted
(it is automatically re-created). To avoid this, append
<code 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
using the new 'page store' mechanism (currently beta).
</p>
......@@ -148,13 +148,13 @@ to be dangerous, they are only supported for situations where performance is mor
than reliability. Those dangerous features are:
</p>
<ul>
<li>Disabling the transaction log mechanism using <code class="notranslate">SET LOG 0</code>.
</li><li>Using the transaction isolation level <code class="notranslate">READ_UNCOMMITTED</code>
(<code class="notranslate">LOCK_MODE 0</code>) while at the same time using multiple
<li>Disabling the transaction log mechanism using <code>SET LOG 0</code>.
</li><li>Using the transaction isolation level <code>READ_UNCOMMITTED</code>
(<code>LOCK_MODE 0</code>) while at the same time using multiple
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.
</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>
<p>
In addition to that, running out of memory should be avoided.
......@@ -165,8 +165,8 @@ Areas that are not fully tested:
</p>
<ul>
<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
<code class="notranslate">AUTO_RECONNECT</code>
</li><li>The features <code>AUTO_SERVER</code> and
<code>AUTO_RECONNECT</code>
</li><li>The MVCC (multi version concurrency) mode
</li><li>Cluster mode, 2-phase commit, savepoints
</li><li>24/7 operation
......@@ -181,7 +181,7 @@ Areas considered experimental are:
</p>
<ul>
<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></ul>
......@@ -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.
This is specially a problem for larger databases.
To close a database, close all connections to it before the application ends, or execute
the command <code class="notranslate">SHUTDOWN</code>.
the command <code>SHUTDOWN</code>.
The database is also closed when the virtual machine exits normally
by using a shutdown hook. However killing a Java process or calling Runtime.halt will prevent this.
The reason why opening is slow in this situations is that indexes are re-created.
If you can not guarantee the database is closed, consider using
<code class="notranslate">SET LOG 2</code> (see SQL Grammar).
<code>SET LOG 2</code> (see SQL Grammar).
</p>
<p>
To find out what the problem is, open the database in embedded mode using the H2 Console.
This will print progress information. If you have many '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.
</p>
<p>
......
......@@ -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>
<p>
The database URL for connecting to a local database is
<code class="notranslate">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
<code>jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code>.
The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working
directory is used as a starting point. The case sensitivity of the path and database name depend on the
operating system, however it is recommended to use lowercase letters only.
The database name must be at least three characters long
(a limitation of <code class="notranslate">File.createTempFile</code>).
To point to the user home directory, use <code class="notranslate">~/</code>, as in: <code class="notranslate">jdbc:h2:~/test</code>.
(a limitation of <code>File.createTempFile</code>).
To point to the user home directory, use <code>~/</code>, as in: <code>jdbc:h2:~/test</code>.
</p>
<br />
......@@ -613,23 +613,23 @@ This database supports the memory-only mode, where the data is not persisted.
</p><p>
In some cases, only one connection to a memory-only database is required.
This means the database to be opened is private. In this case, the database URL is
<code 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.
</p><p>
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
class loader environment.
</p><p>
It is also possible to access a memory-only database remotely
(or from multiple processes in the same machine) using TCP/IP or SSL/TLS.
An example database URL is: <code class="notranslate">jdbc:h2:tcp://localhost/mem:db1</code>.
An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code>.
</p><p>
By default, closing the last connection to a database closes the database.
For an in-memory database, this means the content is lost.
To keep the database open, add <code 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
<code class="notranslate">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</code>.
<code>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</code>.
</p>
<br />
......@@ -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
password-encrypted database:
</p>
<pre class="notranslate">
<pre>
Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test;CIPHER=AES";
String user = "sa";
......@@ -665,13 +665,13 @@ conn = DriverManager.
<h3>Encrypting or Decrypting a Database</h3>
<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.
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
with the file password 'filepwd' and the encryption algorithm AES:
The tool is available from within the H2 Console in the tools section, or you can run it from the command line.
The following command line will encrypt the database <code>test</code> in the user home directory
with the file password <code>filepwd</code> and the encryption algorithm AES:
</p>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.ChangeFileEncryption -dir ~ -db test -cipher AES -encrypt filepwd
</pre>
......@@ -695,10 +695,10 @@ in this case it is up to the application to protect the database files.
</li></ul>
<p>
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:
</p>
<pre class="notranslate">
<pre>
String url = "jdbc:h2:~/test;FILE_LOCK=SOCKET";
</pre>
<p>
......@@ -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
data corruption:
</p>
<pre class="notranslate">
<pre>
String url = "jdbc:h2:~/test;FILE_LOCK=NO";
</pre>
<p>
......@@ -717,15 +717,15 @@ For more information about the algorithms, see
<br />
<h2 id="database_only_if_exists">Opening a Database Only if it Already Exists</h2>
<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.
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
trying to connect. The connection only succeeds when the database already exists.
The complete URL may look like this:
</p>
<pre class="notranslate">
<pre>
String url = "jdbc:h2:/data/sample;IFEXISTS=TRUE";
</pre>
......@@ -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
this slows down the application, for example when it is not possible to keep at least one connection open.
The automatic closing of a database can be delayed or disabled with the SQL statement
<code 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
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:
</p>
<pre class="notranslate">
<pre>
SET DB_CLOSE_DELAY 10
</pre>
<p>
The value -1 means the database is not closed automatically.
The value 0 is the default and means the database is closed when the last connection is closed.
This setting is persistent and can be set by an administrator only.
It is possible to set the value in the database URL: <code 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>
<br />
......@@ -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).
The database URL to disable database closing on exit is:
</p>
<pre class="notranslate">
<pre>
String url = "jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE";
</pre>
......@@ -779,7 +779,7 @@ In some situations, for example when using very large databases (over a few hund
re-creating the index file takes very long.
In these situations it may be better to log changes to the index file,
so that recovery from a corrupted index file is fast.
To enable log index changes, add LOG=2 to the URL, as in <code 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.
The update performance of the database will be reduced when using this option.
</p>
......@@ -789,12 +789,12 @@ The update performance of the database will be reduced when using this option.
<p>
Some applications (for example OpenOffice.org Base) pass some additional parameters
when connecting to the database. Why those parameters are passed is unknown.
The parameters <code class="notranslate">PREFERDOSLIKELINEENDS</code> and
<code class="notranslate">IGNOREDRIVERPRIVILEGES</code> are such examples;
The parameters <code>PREFERDOSLIKELINEENDS</code> and
<code>IGNOREDRIVERPRIVILEGES</code> are such examples;
they are simply ignored to improve the compatibility with OpenOffice.org. If an application
passes other parameters when connecting to the database, usually the database throws an exception
saying the parameter is not supported. It is possible to ignored such parameters by adding
<code class="notranslate">;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL.
<code>;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL.
</p>
<br />
......@@ -802,8 +802,8 @@ saying the parameter is not supported. It is possible to ignored such parameters
<p>
In addition to the settings already described,
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
same as executing the statement <code class="notranslate">SET setting value</code> just after
Adding <code>;setting=value</code> at the end of a database URL is the
same as executing the statement <code>SET setting value</code> just after
connecting. For a list of supported settings, see <a href="grammar.html">SQL Grammar</a>.
</p>
......@@ -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>
<p>
Usually, the database opens log, data and index files with the access mode
<code class="notranslate">rw</code>, meaning
read-write (except for read only databases, where the mode <code class="notranslate">r</code> is used).
<code>rw</code>, meaning
read-write (except for read only databases, where the mode <code>r</code> is used).
To open a database in read-only mode if the files are not read-only, use
<code class="notranslate">ACCESS_MODE_DATA=r</code>.
Also supported are <code class="notranslate">rws</code> and <code class="notranslate">rwd</code>.
The access mode used for log files is set via <code class="notranslate">ACCESS_MODE_LOG</code>;
for data and index files use <code class="notranslate">ACCESS_MODE_DATA</code>.
<code>ACCESS_MODE_DATA=r</code>.
Also supported are <code>rws</code> and <code>rwd</code>.
The access mode used for log files is set via <code>ACCESS_MODE_LOG</code>;
for data and index files use <code>ACCESS_MODE_DATA</code>.
These settings must be specified in the database URL:
</p>
<pre class="notranslate">
<pre>
String url = "jdbc:h2:~/test;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws";
</pre>
<p>
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>
<br />
......@@ -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,
then a lock timeout exception is thrown.
</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,
using the statement <code class="notranslate">SELECT ... FOR UPDATE</code>.
The statements <code class="notranslate">COMMIT</code> and
<code class="notranslate">ROLLBACK</code> releases all open locks.
The commands <code class="notranslate">SAVEPOINT</code> and
<code class="notranslate">ROLLBACK TO SAVEPOINT</code> don't affect locks.
using the statement <code>SELECT ... FOR UPDATE</code>.
The statements <code>COMMIT</code> and
<code>ROLLBACK</code> releases all open locks.
The commands <code>SAVEPOINT</code> and
<code>ROLLBACK TO SAVEPOINT</code> don't affect locks.
The locks are also released when the autocommit mode changes, and for connections with
autocommit set to true (this is the default), locks are released after each statement.
The following statements generate locks:
......@@ -909,9 +909,9 @@ The following statements generate locks:
<p>
The number of seconds until a lock timeout exception is thrown can be
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
<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>
<br />
......@@ -931,7 +931,7 @@ The following files can be created by the database:
</td><td>
Database file.<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>
1 per database
</td></tr>
......@@ -940,7 +940,7 @@ The following files can be created by the database:
</td><td>
Data file.<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>
1 per database
</td></tr>
......@@ -949,7 +949,7 @@ The following files can be created by the database:
</td><td>
Index file.<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>
1 per database
</td></tr>
......@@ -958,7 +958,7 @@ The following files can be created by the database:
</td><td>
Transaction log file.<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>
0 or more per database
</td></tr>
......@@ -967,7 +967,7 @@ The following files can be created by the database:
</td><td>
Database lock file.<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>
1 per database
</td></tr>
......@@ -976,8 +976,8 @@ The following files can be created by the database:
</td><td>
Trace file.<br />
Contains trace information.<br />
Format: <code class="notranslate">&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>
Format: <code>&lt;database&gt;.trace.db</code><br />
If the file is too big, it is renamed to <code>&lt;database&gt;.trace.db.old</code>
</td><td>
1 per database
</td></tr>
......@@ -986,7 +986,7 @@ The following files can be created by the database:
</td><td>
Large object.<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>
1 per value
</td></tr>
......@@ -995,7 +995,7 @@ The following files can be created by the database:
</td><td>
Temporary file.<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>
1 per object
</td></tr>
......@@ -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
automatically if they don't exist.
</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>
<br />
......@@ -1035,14 +1035,14 @@ the index file is rebuilt from scratch.
</p><p>
There is usually only one log file per database. This file grows until the database is closed successfully,
and is then deleted. Or, if the file gets too big, the database switches to another log file (with a higher id).
It is possible to force the log switching by using the <code class="notranslate">CHECKPOINT</code> command.
It is possible to force the log switching by using the <code>CHECKPOINT</code> command.
</p><p>
If the database file is corrupted, because the checksum of a record does not match (for example, if the
file was edited with another application), the database can be opened in recovery mode. In this case,
errors in the database are logged but not thrown. The database should be backed up to a script
and re-built as soon as possible. To open the database in the recovery mode, use a database URL
must contain <code class="notranslate">;RECOVER=1</code>, as in
<code class="notranslate">jdbc:h2:~/test;RECOVER=1</code>. Indexes are rebuilt in this case, and
must contain <code>;RECOVER=1</code>, as in
<code>jdbc:h2:~/test;RECOVER=1</code>. Indexes are rebuilt in this case, and
the summary (object allocation table) is not read in this case, so opening the database takes longer.
</p>
......@@ -1055,8 +1055,8 @@ and tries to be compatible to other databases. There are still a few differences
<p>
In MySQL text columns are case insensitive by default, while in H2 they are case sensitive. However
H2 supports case insensitive columns as well. To create the tables with case insensitive texts, append
<code class="notranslate">IGNORECASE=TRUE</code> to the database URL
(example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code>).
<code>IGNORECASE=TRUE</code> to the database URL
(example: <code>jdbc:h2:~/test;IGNORECASE=TRUE</code>).
</p>
<h3>Compatibility Modes</h3>
......@@ -1068,105 +1068,105 @@ Here is the list of currently supported modes and the differences to the regular
<h3>DB2 Compatibility Mode</h3>
<p>
To use the IBM DB2 mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=DB2</code>
or the SQL statement <code class="notranslate">SET 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>SET MODE DB2</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
</li><li>Support for the syntax <code class="notranslate">[OFFSET .. ROW] [FETCH ... ONLY]</code>
as an alternative for <code class="notranslate">LIMIT .. OFFSET</code>.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>null</code>.
</li><li>Support for the syntax <code>[OFFSET .. ROW] [FETCH ... ONLY]</code>
as an alternative for <code>LIMIT .. OFFSET</code>.
</li><li>Concatenating <code>NULL</code> with another value
results in the other value.
</li></ul>
<h3>Derby Compatibility Mode</h3>
<p>
To use the Apache Derby mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=Derby</code>
or the SQL statement <code class="notranslate">SET 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>SET MODE Derby</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>null</code>.
</li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code>NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code>NULL</code> with another value
results in the other value.
</li></ul>
<h3>HSQLDB Compatibility Mode</h3>
<p>
To use the HSQLDB mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=HSQLDB</code>
or the SQL statement <code class="notranslate">SET MODE HSQLDB</code>.
To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code>
or the SQL statement <code>SET MODE HSQLDB</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>null</code>.
</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.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed.
</li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code>NULL</code> in one of the columns is allowed.
</li></ul>
<h3>MS SQL Server Compatibility Mode</h3>
<p>
To use the MS SQL Server mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=MSSQLServer</code>
or the SQL statement <code class="notranslate">SET 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>SET MODE MSSQLServer</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
</li><li>Identifiers may be quoted using square brackets as in <code class="notranslate">[Test]</code>.
</li><li>For unique indexes, <code class="notranslate">NULL</code> is distinct.
That means only one row with <code class="notranslate">NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code class="notranslate">NULL</code> with another value
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>null</code>.
</li><li>Identifiers may be quoted using square brackets as in <code>[Test]</code>.
</li><li>For unique indexes, <code>NULL</code> is distinct.
That means only one row with <code>NULL</code> in one of the columns is allowed.
</li><li>Concatenating <code>NULL</code> with another value
results in the other value.
</li></ul>
<h3>MySQL Compatibility Mode</h3>
<p>
To use the MySQL mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=MySQL</code>
or the SQL statement <code class="notranslate">SET MODE MySQL</code>.
To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code>
or the SQL statement <code>SET MODE MySQL</code>.
</p>
<ul><li>When inserting data, if a column is defined to be <code class="notranslate">NOT NULL</code>
and <code class="notranslate">NULL</code> is inserted,
<ul><li>When inserting data, if a column is defined to be <code>NOT NULL</code>
and <code>NULL</code> is inserted,
then a 0 (or empty string, or the current timestamp for timestamp columns) value is used.
Usually, this operation is not allowed and an exception is thrown.
</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>When converting a floating point number to an integer, the fractional
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.
</li></ul>
<h3>Oracle Compatibility Mode</h3>
<p>
To use the Oracle mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=Oracle</code>
or the SQL statement <code class="notranslate">SET MODE Oracle</code>.
To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code>
or the SQL statement <code>SET MODE Oracle</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
</li><li>When using unique indexes, multiple rows with <code class="notranslate">NULL</code>
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>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
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.
</li></ul>
<h3>PostgreSQL Compatibility Mode</h3>
<p>
To use the PostgreSQL mode, use the database URL <code class="notranslate">jdbc:h2:~/test;MODE=PostgreSQL</code>
or the SQL statement <code class="notranslate">SET MODE PostgreSQL</code>.
To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code>
or the SQL statement <code>SET MODE PostgreSQL</code>.
</p>
<ul><li>For aliased columns, <code class="notranslate">ResultSetMetaData.getColumnName()</code>
returns the alias name and <code class="notranslate">getTableName()</code> returns
<code class="notranslate">null</code>.
<ul><li>For aliased columns, <code>ResultSetMetaData.getColumnName()</code>
returns the alias name and <code>getTableName()</code> returns
<code>null</code>.
</li><li>When converting a floating point number to an integer, the fractional
digits are not be truncated, but the value is rounded.
</li><li>The system columns <code class="notranslate">CTID</code> and
<code class="notranslate">OID</code> are supported.
</li><li>The system columns <code>CTID</code> and
<code>OID</code> are supported.
</li></ul>
<br />
......@@ -1179,7 +1179,7 @@ occurs when auto-commit is enabled; if auto-commit is disabled, an exception is
<p>
Re-connecting will open a new session. After an automatic re-connect,
variables and local temporary tables definitions (excluding data) are re-created.
The contents of the system table <code 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.
</p>
......@@ -1187,7 +1187,7 @@ contains all client side state that is re-created.
<h2 id="auto_mixed_mode">Automatic Mixed Mode</h2>
<p>
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.
</p>
<p>
......@@ -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
the database first if possible. The first connection automatically starts a server on a random port.
This server allows remote connections, however only to this database (to ensure that,
the client reads <code 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
open, one of them will then start a server (auto-reconnect is enabled automatically).
</p>
<p>
All processes need to have access to the database files.
If the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back.
Explicit client/server connections (using <code 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.
</p>
<p>
......@@ -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
and 2 are typically two different processes (however they could run within the same process).
</p>
<pre class="notranslate">
<pre>
// Application 1:
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
where executed. This database offers the following trace features:
</p>
<ul>
<li>Trace to <code class="notranslate">System.out</code> and/or to a file
</li><li>Support for trace levels <code class="notranslate">OFF, ERROR, INFO, DEBUG</code>
<li>Trace to <code>System.out</code> and/or to a file
</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>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
......@@ -1240,26 +1240,26 @@ where executed. This database offers the following trace features:
<h3>Trace Options</h3>
<p>
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>
(<code class="notranslate">TRACE_LEVEL_SYSTEM_OUT</code>) tracing,
and one for file tracing (<code class="notranslate">TRACE_LEVEL_FILE</code>).
There are two settings, one for <code>System.out</code>
(<code>TRACE_LEVEL_SYSTEM_OUT</code>) tracing,
and one for file tracing (<code>TRACE_LEVEL_FILE</code>).
The trace levels are
0 for <code class="notranslate">OFF</code>,
1 for <code class="notranslate">ERROR</code> (the default),
2 for <code class="notranslate">INFO</code>, and
3 for <code class="notranslate">DEBUG</code>.
A database URL with both levels set to <code class="notranslate">DEBUG</code> is:
0 for <code>OFF</code>,
1 for <code>ERROR</code> (the default),
2 for <code>INFO</code>, and
3 for <code>DEBUG</code>.
A database URL with both levels set to <code>DEBUG</code> is:
</p>
<pre class="notranslate">
<pre>
jdbc:h2:~/test;TRACE_LEVEL_FILE=3;TRACE_LEVEL_SYSTEM_OUT=3
</pre>
<p>
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)
or <code class="notranslate">SET TRACE_LEVEL_FILE level</code> (for file tracing).
<code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for <code>System.out</code> tracing)
or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing).
Example:
</p>
<pre class="notranslate">
<pre>
SET TRACE_LEVEL_SYSTEM_OUT 3
</pre>
......@@ -1267,22 +1267,22 @@ SET TRACE_LEVEL_SYSTEM_OUT 3
<p>
When using a high trace level, the trace file can get very big quickly.
The default size limit is 16 MB, if the trace file exceeds this limit, it is renamed to
<code 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.
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:
</p>
<pre class="notranslate">
<pre>
SET TRACE_MAX_FILE_SIZE 1
</pre>
<h3>Java Code Generation</h3>
<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:
</p>
<pre class="notranslate">
<pre>
...
12-20 20:58:09 jdbc[0]:
/**/dbMeta3.getURL();
......@@ -1291,14 +1291,14 @@ Java source code is generated as well. This simplifies reproducing problems. The
...
</pre>
<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>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.ConvertTraceFile
-traceFile "~/test.trace.db" -javaClass "Test"
</pre>
<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).
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.
......@@ -1309,7 +1309,7 @@ The password is not listed in the trace file and therefore not included in the s
<p>
By default, this database uses its own native 'trace' facility. This facility is called 'trace' and not
'log' within this database to avoid confusion with the transaction log. Trace messages can be
written to both file and <code 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
facility as the application, for example Log4j. To do that, this database support SLF4J.
</p>
......@@ -1322,15 +1322,15 @@ Java logging, x4juli, and Simple Log.
<p>
To enable SLF4J, set the file trace level to 4 in the database URL:
</p>
<pre class="notranslate">
<pre>
jdbc:h2:~/test;TRACE_LEVEL_FILE=4
</pre>
<p>
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.
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>
<br />
......@@ -1338,23 +1338,23 @@ If it does not work, check the file <code class="notranslate">&lt;database&gt;.t
<p>
If the database files are read-only, then the database is read-only as well.
It is not possible to create new tables, add or modify data in this database.
Only <code 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.
Then, make the database files read-only using the operating system.
When you open the database now, it is read-only.
There are two ways an application can find out whether database is read-only:
by calling <code class="notranslate">Connection.isReadOnly()</code>
or by executing the SQL statement <code class="notranslate">CALL READONLY()</code>.
by calling <code>Connection.isReadOnly()</code>
or by executing the SQL statement <code>CALL READONLY()</code>.
</p>
<br />
<h2 id="database_in_zip">Read Only Databases in Zip or Jar File</h2>
<p>
To create a read-only database in a zip file, first create a regular persistent database, and then create a backup.
If you are using a database named 'test', an easy way to do that is using the
<code class="notranslate">Backup</code> tool or the <code class="notranslate">BACKUP</code> SQL statement:
If you are using a database named <code>test</code>, an easy way to do that is using the
<code>Backup</code> tool or the <code>BACKUP</code> SQL statement:
</p>
<pre class="notranslate">
<pre>
BACKUP TO 'data.zip'
</pre>
<p>
......@@ -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,
and directly open the database in the zip file using the following database URL:
</p>
<pre class="notranslate">
<pre>
jdbc:h2:zip:~/data.zip!/test
</pre>
<p>
......@@ -1379,10 +1379,10 @@ a regular database.
If the database needs more disk space, it calls the database event listener if one is installed.
The application may then delete temporary files, or display a message and wait until
the user has resolved the problem. To install a listener, run the SQL statement
<code class="notranslate">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>SET DATABASE_EVENT_LISTENER</code> or use a database URL of the form
<code>jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener'</code>
(the quotes around the class name are required).
See also the <code class="notranslate">DatabaseEventListener</code> API.
See also the <code>DatabaseEventListener</code> API.
</p>
<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
a column is required, create a computed column with the upper-case version of the original column,
and create an index for this column:
</p>
<pre class="notranslate">
<pre>
CREATE TABLE ADDRESS(
ID INT PRIMARY KEY,
NAME VARCHAR,
......@@ -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
column when querying the table:
</p>
<pre class="notranslate">
<pre>
INSERT INTO ADDRESS(ID, NAME) VALUES(1, 'Miller');
SELECT * FROM ADDRESS WHERE UPPER_NAME='MILLER';
</pre>
......@@ -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.
The following code can be used to do that:
</p>
<pre class="notranslate">
<pre>
import java.sql.*;
import java.util.*;
public class Test {
......@@ -1496,18 +1496,18 @@ public class Test {
</pre>
<p>
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>
<h3>Passing the User Name and/or Password in the URL</h3>
<p>
Instead of passing the user name as a separate parameter as in
<code class="notranslate">
<code>
Connection conn = DriverManager.
getConnection("jdbc:h2:~/test", "sa", "123");
</code>
the user name (and/or password) can be supplied in the URL itself:
<code class="notranslate">
<code>
Connection conn = DriverManager.
getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");
</code>
......@@ -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.
Example Java method:
</p>
<pre class="notranslate">
<pre>
package acme;
import java.math.*;
public class Function {
......@@ -1533,35 +1533,35 @@ public class Function {
}
</pre>
<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>
<pre class="notranslate">
<pre>
CREATE ALIAS IS_PRIME FOR "acme.Function.isPrime"
</pre>
<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>
<h3>Function Data Type Mapping</h3>
<p>
Functions that accept non-nullable parameters such as <code class="notranslate">int</code>
will not be called if one of those parameters is <code class="notranslate">NULL</code>.
Instead, the result of the function is <code class="notranslate">NULL</code>.
If the function should be called if a parameter is <code class="notranslate">NULL</code>, you need
to use <code class="notranslate">java.lang.Integer</code> instead.
Functions that accept non-nullable parameters such as <code>int</code>
will not be called if one of those parameters is <code>NULL</code>.
Instead, the result of the function is <code>NULL</code>.
If the function should be called if a parameter is <code>NULL</code>, you need
to use <code>java.lang.Integer</code> instead.
</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>.
There are two special cases: <code class="notranslate">java.lang.Object</code> is mapped to
<code class="notranslate">OTHER</code> (a serialized object). Therefore,
<code class="notranslate">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>:
arrays of any class are mapped to <code class="notranslate">ARRAY</code>.
There are two special cases: <code>java.lang.Object</code> is mapped to
<code>OTHER</code> (a serialized object). Therefore,
<code>java.lang.Object</code> can not be used
to match all SQL types (matching all SQL types is not supported). The second special case is <code>Object[]</code>:
arrays of any class are mapped to <code>ARRAY</code>.
</p>
<h3>Functions that require a Connection</h3>
<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.
When calling the method from within the SQL statement, this connection parameter
does not need to be (can not be) specified.
......@@ -1575,9 +1575,9 @@ and the exception is thrown to the application.
<h3>Functions returning a Result Set</h3>
<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>
<pre class="notranslate">
<pre>
public static ResultSet query(Connection conn, String sql) throws SQLException {
return conn.createStatement().executeQuery(sql);
}
......@@ -1588,9 +1588,9 @@ CALL QUERY('SELECT * FROM TEST');
<h3>Using SimpleResultSet</h3>
<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>
<pre class="notranslate">
<pre>
import org.h2.tools.SimpleResultSet;
...
public static ResultSet simpleResultSet() throws SQLException {
......@@ -1611,13 +1611,13 @@ CALL SIMPLE();
A function that returns a result set can be used like a table.
However, in this case the function is called at least twice:
first while parsing the statement to collect the column names
(with parameters set to 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).
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 class="notranslate">jdbc:default:connection</code>.
<code>jdbc:columnlist:connection</code>. Otherwise, the URL of the connection is
<code>jdbc:default:connection</code>.
</p>
<pre class="notranslate">
<pre>
public static ResultSet getMatrix(Connection conn, Integer size)
throws SQLException {
SimpleResultSet rs = new SimpleResultSet();
......@@ -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.
Triggers can be used for complex consistency checks, or to update related data in the database.
It is also possible to use triggers to simulate materialized views.
For a complete sample application, see <code class="notranslate">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
For a complete sample application, see <code>src/test/org/h2/samples/TriggerSample.java</code>.
A Java trigger must implement the interface <code>org.h2.api.Trigger</code>. The trigger class must be available
in the classpath of the database engine (when using the server mode, it must be in the classpath
of the server).
</p>
<pre class="notranslate">
<pre>
import org.h2.api.Trigger;
...
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 trigger then needs to be defined in the database:
</p>
<pre class="notranslate">
<pre>
CREATE TRIGGER INV_INS AFTER INSERT ON INVOICE
FOR EACH ROW CALL "org.h2.samples.TriggerSample"
</pre>
<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>
<br />
<h2 id="compacting">Compacting a Database</h2>
<p>
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
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:
</p>
<pre class="notranslate">
<pre>
public static void compact(String dir, String dbName,
String user, String password) throws Exception {
String url = "jdbc:h2:" + dir + "/" + dbName;
......@@ -1694,8 +1694,8 @@ public static void compact(String dir, String dbName,
}
</pre>
<p>
See also the sample application <code class="notranslate">org.h2.samples.Compact</code>.
The commands <code class="notranslate">SCRIPT / RUNSCRIPT</code> can be used as well to create a backup
See also the sample application <code>org.h2.samples.Compact</code>.
The commands <code>SCRIPT / RUNSCRIPT</code> can be used as well to create a backup
of a database and re-build the database from the script.
</p>
......@@ -1704,16 +1704,16 @@ of a database and re-build the database from the script.
<p>
The database keeps most frequently used data and index pages in the main memory.
The amount of memory used for caching can be changed using the setting
<code class="notranslate">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 class="notranslate">SET CACHE_SIZE size</code>.
<code>CACHE_SIZE</code>. This setting can be set in the database connection URL
(<code>jdbc:h2:~/test;CACHE_SIZE=131072</code>), or it can be changed at runtime using
<code>SET CACHE_SIZE size</code>.
</p><p>
Also supported is a second level soft reference cache. Rows in this cache are only garbage collected
on low memory. By default the second level cache is disabled. To enable it,
use the prefix <code 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>
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.
</p>
......
......@@ -56,7 +56,7 @@ Initial Developer: H2 Group
<a href="tutorial.html"> Tutorial </a><br />
<a href="features.html"> Features </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="download.html"> Download </a><br />
<br />
......@@ -65,8 +65,8 @@ Initial Developer: H2 Group
<a href="functions.html"> Functions </a><br />
<a href="datatypes.html"> Data Types </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="../h2.pdf"> PDF (1 MB) </a><br />
<br />
<b> Appendix </b><br />
<a href="build.html"> Build </a><br />
......
......@@ -55,7 +55,7 @@ Functions
<c:forEach var="item" items="functionsAll">
<br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate">
<pre>
${item.syntax}
</pre>
<p>${item.text}</p>
......
......@@ -53,7 +53,7 @@ SQL Grammar
<c:forEach var="item" items="commands">
<br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate">
<pre>
${item.syntax}
</pre>
<p>${item.text}</p>
......@@ -64,7 +64,7 @@ ${item.syntax}
<c:forEach var="item" items="otherGrammar">
<br />
<h3 id="${item.link}" class="notranslate">${item.topic}</h3>
<pre class="notranslate">
<pre>
${item.syntax}
</pre>
<p>${item.text}</p>
......@@ -75,7 +75,7 @@ ${item.syntax}
<br />
<h3 id="information_schema" class="notranslate">Information Schema</h3>
<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.
</p>
<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
The table contains one column called X. Both the start and end values are included in the result.
The table is used as follows:
</p>
<pre class="notranslate">
<pre>
SELECT X FROM SYSTEM_RANGE(1, 10);
</pre>
......
......@@ -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
Microsoft .NET technology). The following JaQu code:
</p>
<pre class="notranslate">
<pre>
Product p = new Product();
List&lt;Product&gt; soldOutProducts =
db.from(p).where(p.unitsInStock).is(0).select();
......@@ -33,7 +33,7 @@ List&lt;Product&gt; soldOutProducts =
<p>
stands for the SQL statement:
</p>
<pre class="notranslate">
<pre>
SELECT * FROM PRODUCTS P
WHERE P.UNITS_IN_STOCK = 0
</pre>
......@@ -56,8 +56,8 @@ JaQu provides full control over when and what SQL statements are executed.
<h3>Restrictions</h3>
<p>
Primitive types (eg. <code class="notranslate">boolean, int, long, double</code>) are not supported.
Use <code class="notranslate">java.lang.Boolean, Integer, Long, Double</code> instead.
Primitive types (eg. <code>boolean, int, long, double</code>) are not supported.
Use <code>java.lang.Boolean, Integer, Long, Double</code> instead.
</p>
<h3>Why in Java?</h3>
......@@ -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.
JaQu is not part of the h2 jar file, however the source code is included in H2, under:
</p>
<ul><li><code class="notranslate">src/test/org/h2/test/jaqu/*</code> (samples and tests)
</li><li><code class="notranslate">src/tools/org/h2/jaqu/*</code> (framework)
<ul><li><code>src/test/org/h2/test/jaqu/*</code> (samples and tests)
</li><li><code>src/tools/org/h2/jaqu/*</code> (framework)
</li></ul>
<h2>Building the JaQu library</h2>
<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>
<h2>Requirements</h2>
......@@ -88,7 +88,7 @@ work with any database that supports the JDBC API.
</p>
<h2>Example Code</h2>
<pre class="notranslate">
<pre>
package org.h2.test.jaqu;
import java.math.BigDecimal;
import java.util.List;
......@@ -226,10 +226,10 @@ public class Test {
<p>
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,
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:
</p>
<pre class="notranslate">
<pre>
public class Product implements Table {
public Integer productId;
......@@ -247,7 +247,7 @@ public class Product implements Table {
}
</pre>
<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.
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).
......@@ -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).
The planned syntax is:
</p>
<pre class="notranslate">
<pre>
long count = db.from(co).
where(new Filter() { public boolean where() {
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
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,
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>
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.
......
......@@ -102,12 +102,12 @@ some time after opening a database to ensure the database files are not opened b
<p>
Version 1.8.0.10 was used for the test.
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 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:
</p>
<pre class="notranslate">
<pre>
SELECT COUNT(DISTINCT S_I_ID) FROM ORDER_LINE, STOCK
WHERE OL_W_ID=? AND OL_D_ID=? AND OL_O_ID&lt;? AND OL_O_ID&gt;=?
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.
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.
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,
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
......@@ -135,7 +135,7 @@ than half as fast as H2 in default mode.
<h4>PostgreSQL</h4>
<p>
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>.
PostgreSQL is run in server mode. It looks like the base performance is slower than
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
<p>
Version 5.1.34-community was used for the test.
MySQL was run with the InnoDB backend.
The setting <code class="notranslate">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
The setting <code>innodb_flush_log_at_trx_commit</code>
(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.
For small transactions (when autocommit is on) this is really slow.
But many use cases use small or relatively small transactions.
Too bad this setting is not listed in the configuration wizard,
and it always overwritten when using the wizard.
You need to change this setting manually in the file <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.
</p>
......@@ -178,7 +178,7 @@ SQLite was not tested because the JDBC driver doesn't support transactions.
<p>
This test was executed as follows:
</p>
<pre class="notranslate">
<pre>
build benchmark
</pre>
......@@ -246,8 +246,8 @@ each database tested, and each database runs in a different process (sequentiall
<h4>Transaction Commit / Durability</h4>
<p>
Durability means transaction committed to the database will not be lost.
Some databases (for example MySQL) try to enforce this by default by
calling <code class="notranslate">fsync()</code> to flush the buffers, but
Some databases (for example MySQL) try to enforce this by default by
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,
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.
......@@ -307,13 +307,13 @@ There are a few problems with the PolePosition test:
<ul><li>
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
<code class="notranslate">poleposition-0.20/lib/hsqldb.jar</code> with a newer version (for example
<code class="notranslate">hsqldb-1.8.0.7.jar</code>),
<code>poleposition-0.20/lib/hsqldb.jar</code> with a newer version (for example
<code>hsqldb-1.8.0.7.jar</code>),
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>
in the file <code class="notranslate">Jdbc.properties</code>.
<code>hsqldb.connecturl=jdbc:hsqldb:file:data/hsqldb/dbbench2;hsqldb.default_table_type=cached;sql.enforce_size=true</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).
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.
Unfortunately, the PolePosition test does not take this into account.
</li></ul>
......@@ -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).
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
<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>
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>
A simple way to profile an application is to use the built-in profiling tool of java. Example:
</p>
<pre class="notranslate">
<pre>
java -Xrunhprof:cpu=samples,depth=16 com.acme.Test
</pre>
<p>
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
run <code class="notranslate">jstack &lt;pid&gt;</code> or <code class="notranslate">kill -QUIT &lt;pid&gt;</code> (Linux) or press
a number of full thread dumps. To do that, first run <code>jps -l</code> to get the process id, and then
run <code>jstack &lt;pid&gt;</code> or <code>kill -QUIT &lt;pid&gt;</code> (Linux) or press
Ctrl+C (Windows).
</p>
<br />
<h2 id="database_profiling">Database Profiling</h2>
<p>
The <code class="notranslate">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 <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>java -Xrunhprof</code>.
As an example, execute the the following script using the H2 Console:
</p>
<pre class="notranslate">
<pre>
SET TRACE_LEVEL_FILE 3;
DROP TABLE IF EXISTS TEST;
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;
</pre>
<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>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.ConvertTraceFile
-traceFile "~/test.trace.db" -script "~/test.sql"
</pre>
<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):
</p>
<pre class="notranslate">
<pre>
-----------------------------------------
-- SQL Statement Statistics
-- time: total time in milliseconds (accumulated)
......@@ -390,7 +390,7 @@ following profiling data (results vary):
<h3>Use a Modern JVM</h3>
<p>
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.
</p>
......@@ -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,
that means even if somebody would store a virus in a database file, this would
be harmless (when the virus does not run, it cannot spread).
Some virus scanners allow 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>
<h3>Using the Trace Options</h3>
......@@ -415,16 +415,16 @@ For more information, see <a href="features.html#trace_options">Using the Trace
<h3>Index Usage</h3>
<p>
This database uses indexes to improve the performance of
<code class="notranslate">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,
This database uses indexes to improve the performance of
<code>SELECT, UPDATE, DELETE</code>.
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.
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.
The results are sorted in memory if required.
Indexes are created automatically for primary key and unique constraints.
Indexes are also created for foreign key constraints, if required.
For other columns, indexes need to be created manually using the <code class="notranslate">CREATE INDEX</code> statement.
For other columns, indexes need to be created manually using the <code>CREATE INDEX</code> statement.
</p>
<h3>Optimizer</h3>
......@@ -442,34 +442,34 @@ Only left-deep plans are evaluated.
After the statement is parsed, all expressions are simplified automatically if possible. Operations
are evaluated only once if all parameters are constant. Functions are also optimized, but only
if the function is constant (always returns the same result for the same parameter values).
If the <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>
<h3>COUNT(*) Optimization</h3>
<p>
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
queries of the form <code class="notranslate">SELECT COUNT(*) FROM table</code>.
However, this is only possible if no <code>WHERE</code> clause is used, that means it only works for
queries of the form <code>SELECT COUNT(*) FROM table</code>.
</p>
<h3>Updating Optimizer Statistics / Column Selectivity</h3>
<p>
When executing a query, at most one index per joined table can be used.
If the same table is joined multiple times, for each join only one index is used.
Example: for the query
<code class="notranslate">SELECT * FROM TEST T1, TEST T2 WHERE T1.NAME='A' AND T2.ID=T1.ID</code>,
Example: for the query
<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.
</p><p>
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,
then two indexes could be used for the query <code class="notranslate">SELECT * FROM TEST WHERE NAME='A' AND FIRSTNAME='B'</code>,
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>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.
Which index is used depends on the selectivity of the column. The selectivity describes the 'uniqueness' of
values in a column. A selectivity of 100 means each value appears only once, and a selectivity of 1 means
the same value appears in many or most rows. For the query above, the index on NAME should be used
if the table contains more distinct names than first names.
</p><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.
</p>
......@@ -480,21 +480,21 @@ queries and data manipulation.
</p>
<p>In-memory indexes are automatically used
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
problems for large tables.
</p>
<p>
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>)
but not range scan (<code class="notranslate">WHERE ID &lt; ?</code>). To use hash indexes, use HASH as in:
<code class="notranslate">CREATE UNIQUE HASH INDEX</code> and
<code class="notranslate">CREATE TABLE ...(ID INT PRIMARY KEY HASH,...)</code>.
regular indexes. However, hash indexes only supports direct lookup (<code>WHERE ID = ?</code>)
but not range scan (<code>WHERE ID &lt; ?</code>). To use hash indexes, use HASH as in:
<code>CREATE UNIQUE HASH INDEX</code> and
<code>CREATE TABLE ...(ID INT PRIMARY KEY HASH,...)</code>.
</p>
<h3>Optimization Examples</h3>
<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.
</p>
......@@ -508,17 +508,17 @@ the second level soft reference cache. See also <a href="features.html#cache_set
<p>
Each data type has different storage and performance characteristics:
</p>
<ul><li>The <code class="notranslate">DECIMAL/NUMERIC</code> type is slower
and requires more storage than the <code class="notranslate">REAL</code> and <code class="notranslate">DOUBLE</code> types.
<ul><li>The <code>DECIMAL/NUMERIC</code> type is slower
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>See <a href="advanced.html#large_objects">Large Objects</a> for information on
<code class="notranslate">BINARY</code> vs. <code class="notranslate">BLOB</code>
and <code class="notranslate">VARCHAR</code> vs. <code class="notranslate">CLOB</code> performance.
</li><li>Parsing and formatting takes longer for the
<code class="notranslate">TIME</code>, <code class="notranslate">DATE</code>, and
<code class="notranslate">TIMESTAMP</code> types than the numeric types.
</li><li><code class="notranslate">SMALLINT/TINYINT/BOOLEAN</code> are not significantly smaller or faster
to work with than <code class="notranslate">INTEGER</code> in most modes.
</li><li>See <a href="advanced.html#large_objects">Large Objects</a> for information on
<code>BINARY</code> vs. <code>BLOB</code>
and <code>VARCHAR</code> vs. <code>CLOB</code> performance.
</li><li>Parsing and formatting takes longer for the
<code>TIME</code>, <code>DATE</code>, and
<code>TIMESTAMP</code> types than the numeric types.
</li><li><code>SMALLINT/TINYINT/BOOLEAN</code> are not significantly smaller or faster
to work with than <code>INTEGER</code> in most modes.
</li></ul>
<br />
......@@ -526,14 +526,14 @@ Each data type has different storage and performance characteristics:
<p>
To speed up large imports, consider using the following options temporarily:
</p>
<ul><li><code class="notranslate">SET CACHE_SIZE</code> (a large cache is faster)
</li><li><code class="notranslate">SET LOCK_MODE 0</code> (disable locking)
</li><li><code class="notranslate">SET LOG 0</code> (disable the transaction log)
</li><li><code class="notranslate">SET UNDO_LOG 0</code> (disable the session undo log)
<ul><li><code>SET CACHE_SIZE</code> (a large cache is faster)
</li><li><code>SET LOCK_MODE 0</code> (disable locking)
</li><li><code>SET LOG 0</code> (disable the transaction log)
</li><li><code>SET UNDO_LOG 0</code> (disable the session undo log)
</li></ul>
<p>
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.
</p>
......
......@@ -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:
</p>
<ul>
<li>Add the <code class="notranslate">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>The database URL <code class="notranslate">jdbc:h2:~/test</code> opens the database 'test' in your user home directory
<li>Add the <code>h2*.jar</code> to the classpath (H2 does not have any dependencies)
</li><li>Use the JDBC driver class: <code>org.h2.Driver</code>
</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></ul>
......
......@@ -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 />
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).
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>
</tr>
<tr>
<td>Windows</td>
<td>
Open a file browser, navigate to <code class="notranslate">h2/bin</code>, and
double click on <code class="notranslate">h2.bat</code>.<br />
Open a file browser, navigate to <code>h2/bin</code>, and
double click on <code>h2.bat</code>.<br />
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
(URL: <code class="notranslate">http://localhost:8082</code>).
(URL: <code>http://localhost:8082</code>).
</td>
</tr>
<tr>
<td>Any</td>
<td>
Double click on the <code class="notranslate">h2*.jar</code> file.
This only works if the <code class="notranslate">.jar</code> suffix is associated with java.
Double click on the <code>h2*.jar</code> file.
This only works if the <code>.jar</code> suffix is associated with java.
</td>
</tr>
<tr>
<td>Any</td>
<td>
Open a console window, navigate to the directory <code class="notranslate">h2/bin</code> and type:
<pre class="notranslate">java -cp h2*.jar org.h2.tools.Server</pre>
Open a console window, navigate to the directory <code>h2/bin</code> and type:
<pre>java -cp h2*.jar org.h2.tools.Server</pre>
</td>
</tr>
</table>
......@@ -127,7 +127,7 @@ To change this, go to 'Preferences' and select 'Allow connections from other com
<p>
To find out which version of Java is installed, open a command prompt and type:
</p>
<pre class="notranslate">
<pre>
java -version
</pre>
<p>
......@@ -138,7 +138,7 @@ If you get an error message, you may need to add the Java binary directory to th
<p>
You can only start one instance of the H2 Console,
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),
but this is usually not required as the console supports multiple concurrent connections.
</p>
......@@ -146,8 +146,8 @@ but this is usually not required as the console supports multiple concurrent con
<h3>Using another Port</h3>
<p>
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
in the user directory (for Windows, this is usually in "Documents and Settings/&lt;username&gt;").
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 <code>Documents and Settings/&lt;username&gt;</code>).
The relevant entry is webPort.
</p>
......@@ -155,10 +155,10 @@ The relevant entry is webPort.
<p>
If the server started successfully, you can connect to it using a web browser.
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:
<code class="notranslate">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>.
<code>http://192.168.0.2:8082</code>.
If you enabled SSL on the server side, the URL needs to start with <code>https://</code>.
</p>
<h3>Multiple Concurrent Sessions</h3>
......@@ -186,14 +186,14 @@ by clicking on the message.
<h3>Adding Database Drivers</h3>
<p>
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
<code class="notranslate">C:\Programs\hsqldb\lib\hsqldb.jar</code>, set the environment variable
<code class="notranslate">H2DRIVERS</code> to
<code class="notranslate">C:\Programs\hsqldb\lib\hsqldb.jar</code>.
<code>C:\Programs\hsqldb\lib\hsqldb.jar</code>, set the environment variable
<code>H2DRIVERS</code> to
<code>C:\Programs\hsqldb\lib\hsqldb.jar</code>.
</p><p>
Multiple drivers can be set; each entry needs to be separated with a <code class="notranslate">;</code> (Windows)
or <code class="notranslate">:</code> (other operating systems).
Multiple drivers can be set; each entry needs to be separated with a <code>;</code> (Windows)
or <code>:</code> (other operating systems).
Spaces in the path names are supported. The settings must not be quoted.
</p>
......@@ -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>
<p>
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.
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>
<h3>Disconnecting and Stopping the Application</h3>
......@@ -228,8 +228,8 @@ or close the console window.
<h2 id="console_settings">Settings of the H2 Console</h2>
<p>
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.
For Windows installations, the user home directory is usually <code class="notranslate">C:\Documents and Settings\[username]</code>.
called <code>.h2.server.properties</code> in you user home directory.
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.
</p>
......@@ -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,
and then get a connection. A simple way to do that is using the following code:
</p>
<pre class="notranslate">
<pre>
import java.sql.*;
public class Test {
public static void main(String[] a)
......@@ -253,12 +253,12 @@ public class Test {
}
</pre>
<p>
This code first loads the driver (<code class="notranslate">Class.forName(...)</code>)
and then opens a connection (using <code class="notranslate">DriverManager.getConnection()</code>).
The driver name is <code class="notranslate">"org.h2.Driver"</code>.
The database URL always needs to start with <code class="notranslate">jdbc:h2:</code>
to be recognized by this database. The second parameter in the <code class="notranslate">getConnection()</code> call
is the user name (<code class="notranslate">sa</code> for System Administrator in this example). The third parameter is the password.
This code first loads the driver (<code>Class.forName(...)</code>)
and then opens a connection (using <code>DriverManager.getConnection()</code>).
The driver name is <code>"org.h2.Driver"</code>.
The database URL always needs to start with <code>jdbc:h2:</code>
to be recognized by this database. The second parameter in the <code>getConnection()</code> call
is the user name (<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.
</p>
......@@ -275,25 +275,24 @@ the administrator of this database.
<p>
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).
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>
<h3>Starting the Server Tool from Command Line</h3>
<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>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Server
</pre>
<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>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Server -?
</pre>
<p>
There are options available to use other ports, and start or not start
parts. For details, see the API documentation of the server tool.
There are options available to use other ports, and start or not start parts.
</p>
<h3>Connecting to the TCP Server</h3>
......@@ -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:
</p>
<ul>
<li>JDBC driver class: <code class="notranslate">org.h2.Driver</code>
</li><li>Database URL: <code class="notranslate">jdbc:h2:tcp://localhost/~/test</code>
<li>JDBC driver class: <code>org.h2.Driver</code>
</li><li>Database URL: <code>jdbc:h2:tcp://localhost/~/test</code>
</li></ul>
<p>
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>
Servers can also be started and stopped from within an application. Sample code:
</p>
<pre class="notranslate">
<pre>
import org.h2.tools.Server;
...
// start the TCP Server
......@@ -327,13 +326,13 @@ server.stop();
The TCP server can be stopped from another process.
To stop the server from the command line, run:
</p>
<pre class="notranslate">
<pre>
java org.h2.tools.Server -tcpShutdown tcp://localhost:9092
</pre>
<p>
To stop the server from a user application, use the following code:
</p>
<pre class="notranslate">
<pre>
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094");
</pre>
<p>
......@@ -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,
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.
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).
</p>
......@@ -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
<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
is also available at <code class="notranslate">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.
is also available at <code>src/tools/org/hibernate/dialect/H2Dialect.java.txt</code>.
You can rename it to <code>H2Dialect.java</code> and include this as a patch in your application.
</p>
<br />
<h2 id="using_toplink">Using TopLink and Glassfish</h2>
<p>
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,
or by editing the file <code class="notranslate">sun-resources.xml</code>: at element
<code class="notranslate">jdbc-connection-pool</code>, set the attribute
<code class="notranslate">datasource-classname</code> to <code class="notranslate">org.h2.jdbcx.JdbcDataSource</code>.
or by editing the file <code>sun-resources.xml</code>: at element
<code>jdbc-connection-pool</code>, set the attribute
<code>datasource-classname</code> to <code>org.h2.jdbcx.JdbcDataSource</code>.
</p>
<p>
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
<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.
To enable it, change the following setting in persistence.xml:
</p>
<pre class="notranslate">
<pre>
&lt;property
name="toplink.target-database"
value="oracle.toplink.essentials.platform.database.H2Platform"/>
</pre>
<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>
<br />
......@@ -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
clustered mode). Tomcat uses multiple threads and multiple
classloaders. If multiple applications access the same database at the
same time, you need to put the database jar in the <code class="notranslate">shared/lib</code> or
<code class="notranslate">server/lib</code> directory. It is a good idea to open the database when the
same time, you need to put the database jar in the <code>shared/lib</code> or
<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.
If using multiple applications, only one (any) of them needs to do
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
<h3>Using a Servlet Listener to Start and Stop a Database</h3>
<p>
Add the h2*.jar file to your web application, and
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):
add the following snippet to your web.xml file (between the
<code>context-param</code> and the <code>filter</code> section):
</p>
<pre class="notranslate">
<pre>
&lt;listener>
&lt;listener-class>org.h2.server.web.DbStarter&lt;/listener-class>
&lt;/listener>
</pre>
<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
using the database URL <code class="notranslate">jdbc:h2:~/test</code>,
user name <code class="notranslate">sa</code>, and password <code class="notranslate">sa</code>.
using the database URL <code>jdbc:h2:~/test</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:
</p>
<pre class="notranslate">
<pre>
Connection conn = getServletContext().getAttribute("connection");
</pre>
<p>
<code class="notranslate">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>.
<code>DbStarter</code> can also start the TCP server, however this is disabled by default.
To enable it, use the parameter <code>db.tcpServer</code> in the file <code>web.xml</code>.
Here is the complete list of options.
These options need to be placed between the <code class="notranslate">description</code> tag
and the <code class="notranslate">listener</code> / <code class="notranslate">filter</code> tags:
These options need to be placed between the <code>description</code> tag
and the <code>listener</code> / <code>filter</code> tags:
</p>
<pre class="notranslate">
<pre>
&lt;context-param>
&lt;param-name>db.url&lt;/param-name>
&lt;param-value>jdbc:h2:~/test&lt;/param-value>
......@@ -465,16 +464,16 @@ and the <code class="notranslate">listener</code> / <code class="notranslate">fi
</pre>
<p>
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>
<h3>Using the H2 Console Servlet</h3>
<p>
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
add the following configuration to your <code class="notranslate">web.xml</code>:
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>web.xml</code>:
</p>
<pre class="notranslate">
<pre>
&lt;servlet&gt;
&lt;servlet-name&gt;H2Console&lt;/servlet-name&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>
&lt;/servlet-mapping&gt;
</pre>
<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>
To create a web application with just the H2 Console, run the following command:
</p>
<pre class="notranslate">
<pre>
build warConsole
</pre>
<br />
<h2 id="csv">CSV (Comma Separated Values) Support</h2>
<p>
The CSV file support can be used inside the database using the functions
<code class="notranslate">CSVREAD</code> and <code class="notranslate">CSVWRITE</code>,
The CSV file support can be used inside the database using the functions
<code>CSVREAD</code> and <code>CSVWRITE</code>,
or it can be used outside the database as a standalone tool.
</p>
<h3>Writing a CSV File from Within a Database</h3>
<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:
</p>
<pre class="notranslate">
<pre>
CREATE TABLE TEST(ID INT, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World');
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>
<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>
<pre class="notranslate">
<pre>
SELECT * FROM CSVREAD('test.csv');
</pre>
<h3>Writing a CSV File from a Java Application</h3>
<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:
</p>
<pre class="notranslate">
<pre>
import java.sql.*;
import org.h2.tools.Csv;
import org.h2.tools.SimpleResultSet;
......@@ -548,7 +547,7 @@ public class TestCsv {
It is possible to read a CSV file without opening a database.
Example:
</p>
<pre class="notranslate">
<pre>
import java.sql.*;
import org.h2.tools.Csv;
public class TestCsv {
......@@ -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.
However, this is not recommended while the database is in use. Also, the database files are not human readable
and quite large. The recommended way to backup a database is to create a compressed SQL script file.
This can be done using the Script tool:
This can be done using the <code>Script</code> tool:
</p>
<pre class="notranslate">
<pre>
java org.h2.tools.Script -url jdbc:h2:~/test -user sa -script test.zip -options compression zip
</pre>
<p>
It is also possible to use the SQL command <code class="notranslate">SCRIPT</code> to create the backup of the database.
For more information about the options, see the SQL command <code class="notranslate">SCRIPT</code>.
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>SCRIPT</code>.
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.
</p>
<h3>Restore from a Script</h3>
<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>
<pre class="notranslate">
<pre>
java org.h2.tools.RunScript -url jdbc:h2:~/test -user sa -script test.zip -options compression zip
</pre>
<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 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
<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.
</p>
<h3>Online Backup</h3>
<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.
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
backup is transactionally consistent:
</p>
<pre class="notranslate">
<pre>
BACKUP TO 'backup.zip'
</pre>
<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.
</p>
<p>
......@@ -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,
start it with the parameter '-?', for example:
</p>
<pre class="notranslate">
<pre>
java -cp h2*.jar org.h2.tools.Backup -?
</pre>
<p>
The command line tools are:
</p>
<ul><li><code class="notranslate">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 class="notranslate">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 class="notranslate">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 class="notranslate">Recover</code> helps recovering a corrupted database.
</li><li><code class="notranslate">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 class="notranslate">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 class="notranslate">Shell</code> is a command line database tool.
<ul><li><code>Backup</code> creates a backup of a database.
</li><li><code>ChangeFileEncryption</code> allows changing the file encryption password or algorithm of a database.
</li><li><code>Console</code> starts the browser based H2 Console.
</li><li><code>ConvertTraceFile</code> converts a .trace.db file to a Java application and SQL script.
</li><li><code>CreateCluster</code> creates a cluster from a standalone database.
</li><li><code>DeleteDbFiles</code> deletes all files belonging to a database.
</li><li><code>Recover</code> helps recovering a corrupted database.
</li><li><code>Restore</code> restores a backup of a database.
</li><li><code>RunScript</code> runs a SQL script against a database.
</li><li><code>Script</code> allows converting a database to a SQL script for backup or migration.
</li><li><code>Server</code> is used in the server mode to start a H2 server.
</li><li><code>Shell</code> is a command line database tool.
</li></ul>
<p>
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:
</li><li>Click [OK] (as much as needed), stop OpenOffice (including the Quickstarter)
</li><li>Start OpenOffice Base
</li><li>Connect to an existing database; select [JDBC]; [Next]
</li><li>Example datasource URL: <code class="notranslate">jdbc:h2:~/test</code>
</li><li>JDBC driver class: <code class="notranslate">org.h2.Driver</code>
</li><li>Example datasource URL: <code>jdbc:h2:~/test</code>
</li><li>JDBC driver class: <code>org.h2.Driver</code>
</li></ul>
<p>
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" :
</p>
<ul><li>Click [File], [New], [Database].
</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>JDBC driver class: <code class="notranslate">org.h2.Driver</code>
</li><li>Example datasource URL: <code>jdbc:h2:~/test</code>
</li><li>JDBC driver class: <code>org.h2.Driver</code>
</li></ul>
<p>
Another solution to use H2 in NeoOffice is:
......@@ -717,11 +716,11 @@ See also <a href="http://wiki.services.openoffice.org/wiki/Extensions_developmen
<p>
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
exception will occur: <code class="notranslate">java.security.AccessControlException</code>:
access denied (<code class="notranslate">java.io.FilePermission ... read</code>).
exception will occur: <code>java.security.AccessControlException</code>:
access denied (<code>java.io.FilePermission ... read</code>).
Example permission tags:
</p>
<pre class="notranslate">
<pre>
&lt;security>
&lt;all-permissions/>
&lt;/security>
......@@ -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,
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
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>
<pre class="notranslate">
<pre>
import java.sql.*;
import org.h2.jdbcx.JdbcConnectionPool;
public class Test {
......@@ -768,7 +767,7 @@ tables in the database.
<p>
To initialize, call:
</p>
<pre class="notranslate">
<pre>
CREATE ALIAS IF NOT EXISTS FT_INIT FOR "org.h2.fulltext.FullText.init";
CALL FT_INIT();
</pre>
......@@ -776,7 +775,7 @@ CALL FT_INIT();
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:
</p>
<pre class="notranslate">
<pre>
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello World');
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
in this case all columns are indexed. The index is updated in realtime.
To search the index, use the following query:
</p>
<pre class="notranslate">
<pre>
SELECT * FROM FT_SEARCH('Hello', 0, 0);
</pre>
<p>
This will produce a result set that contains the query needed to retrieve the data:
</p>
<pre class="notranslate">
<pre>
QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre>
<p>
To get the raw data, use <code class="notranslate">FT_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code class="notranslate">SCHEMA</code> (the schema name),
<code class="notranslate">TABLE</code> (the table name),
<code class="notranslate">COLUMNS</code> (an array of column names), and
<code class="notranslate">KEYS</code> (an array of objects).
To get the raw data, use <code>FT_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code>SCHEMA</code> (the schema name),
<code>TABLE</code> (the table name),
<code>COLUMNS</code> (an array of column names), and
<code>KEYS</code> (an array of objects).
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>
</p>
<p>
You can also call the index from within a Java application:
</p>
<pre class="notranslate">
<pre>
org.h2.fulltext.FullText.search(conn, text, limit, offset);
org.h2.fulltext.FullText.searchData(conn, text, limit, offset);
</pre>
......@@ -817,11 +816,11 @@ org.h2.fulltext.FullText.searchData(conn, text, limit, offset);
<p>
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
jar file to the environment variables <code class="notranslate">H2DRIVERS</code> or
<code class="notranslate">CLASSPATH</code>.
jar file to the environment variables <code>H2DRIVERS</code> or
<code>CLASSPATH</code>.
To initialize the Lucene fulltext search in a database, call:
</p>
<pre class="notranslate">
<pre>
CREATE ALIAS IF NOT EXISTS FTL_INIT FOR "org.h2.fulltext.FullTextLucene.init";
CALL FTL_INIT();
</pre>
......@@ -829,7 +828,7 @@ CALL FTL_INIT();
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:
</p>
<pre class="notranslate">
<pre>
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR);
INSERT INTO TEST VALUES(1, 'Hello World');
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
in this case all columns are indexed. The index is updated in realtime. To search the index,
use the following query:
</p>
<pre class="notranslate">
<pre>
SELECT * FROM FTL_SEARCH('Hello', 0, 0);
</pre>
<p>
This will produce a result set that contains the query needed to retrieve the data:
</p>
<pre class="notranslate">
<pre>
QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre>
<p>
To get the raw data, use <code class="notranslate">FTL_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code class="notranslate">SCHEMA</code> (the schema name),
<code class="notranslate">TABLE</code> (the table name),
<code class="notranslate">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:
<code class="notranslate">SELECT T.* FROM FTL_SEARCH_DATA('Hello', 0, 0) FT, TEST T
To get the raw data, use <code>FTL_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code>SCHEMA</code> (the schema name),
<code>TABLE</code> (the table name),
<code>COLUMNS</code> (an array of column names),
and <code>KEYS</code> (an array of objects). To join a table, use a join as in:
<code>SELECT T.* FROM FTL_SEARCH_DATA('Hello', 0, 0) FT, TEST T
WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code>
</p>
<p>
You can also call the index from within a Java application:
</p>
<pre class="notranslate">
<pre>
org.h2.fulltext.FullTextLucene.search(conn, text, limit, offset);
org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset);
</pre>
......@@ -868,22 +867,22 @@ org.h2.fulltext.FullTextLucene.searchData(conn, text, limit, offset);
<br />
<h2 id="user_defined_variables">User-Defined Variables</h2>
<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
from within the session in which they are defined. A value is usually assigned using the SET command:
</p>
<pre class="notranslate">
<pre>
SET @USER = 'Joe';
</pre>
<p>
The value can also be changed using the SET() method. This is useful in queries:
</p>
<pre class="notranslate">
<pre>
SET @TOTAL = NULL;
SELECT X, SET(@TOTAL, IFNULL(@TOTAL, 1.) * X) F FROM SYSTEM_RANGE(1, 50);
</pre>
<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
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.
......@@ -894,7 +893,7 @@ There are no restrictions on the assigned values; large objects (LOBs) are suppo
<p>
Date, time and timestamp values support ISO 8601 formatting, including time zone:
</p>
<pre class="notranslate">
<pre>
CALL TIMESTAMP '2008-01-01 12:00:00+01:00';
</pre>
<p>
......@@ -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).
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,
you need to create a SQL script file using the <code class="notranslate">SCRIPT</code> command or
<code class="notranslate">Script</code> tool, and then load
the database using the <code class="notranslate">RUNSCRIPT</code> command
or the <code class="notranslate">RunScript</code> tool in the new time zone.
you need to create a SQL script file using the <code>SCRIPT</code> command or
<code>Script</code> tool, and then load
the database using the <code>RUNSCRIPT</code> command
or the <code>RunScript</code> tool in the new time zone.
</p>
<br />
......@@ -913,7 +912,7 @@ or the <code class="notranslate">RunScript</code> tool in the new time zone.
<p>
Use the following configuration to start and stop the H2 TCP server using the Spring Framework:
</p>
<pre class="notranslate">
<pre>
&lt;bean id = "org.h2.tools.Server"
class="org.h2.tools.Server"
factory-method="createTcpServer"
......@@ -923,7 +922,7 @@ Use the following configuration to start and stop the H2 TCP server using the Sp
&lt;/bean&gt;
</pre>
<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>
<!-- [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
/*
replace class="n" with class="notranslate" for website
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...
documentation: rolling review at advanced.html (alphabetically)
mvcc merge problem
......
......@@ -148,6 +148,8 @@ public class WebSite {
if (web) {
page = StringUtils.replaceAll(page, TRANSLATE_START, "");
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");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论