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

Documentation: added notranslate tags

上级 4e9eebfd
......@@ -104,7 +104,8 @@ Features
</li><li>Transaction support (read committed and serializable transaction isolation), 2-phase-commit
</li><li>Multiple connections, table level locking
</li><li>Cost based optimizer, using a genetic algorithm for complex queries, zero-administration
</li><li>Scrollable and updatable result set support, large result set, external result sorting, functions can return a result set
</li><li>Scrollable and updatable result set support, large result set, external result sorting,
functions can return a result set
</li><li>Encrypted database (AES or XTEA), SHA-256 password encryption, encryption functions, SSL
</li></ul>
......@@ -119,15 +120,19 @@ Features
</li><li>Sequence and autoincrement columns, computed columns (can be used for function based indexes)
</li><li>ORDER BY, GROUP BY, HAVING, UNION, LIMIT, TOP
</li><li>Collation support, users, roles
</li><li>Compatibility modes for IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL.
</li><li>Compatibility modes for IBM DB2, Apache Derby, HSQLDB,
MS SQL Server, MySQL, Oracle, and PostgreSQL.
</li></ul>
<h3>Security Features</h3>
<ul>
<li>Includes a solution for the SQL injection problem
</li><li>User password authentication uses SHA-256 and salt
</li><li>For server mode connections, user passwords are never transmitted in plain text over the network (even when using insecure connections; this only applies to the TCP server and not to the H2 Console however; it also doesn't apply if you set the password in the database URL)
</li><li>All database files (including script files that can be used to backup data) can be encrypted using AES-256 and XTEA encryption algorithms
</li><li>For server mode connections, user passwords are never transmitted in plain text over the network
(even when using insecure connections; this only applies to the TCP server and not to the H2 Console however;
it also doesn't apply if you set the password in the database URL)
</li><li>All database files (including script files that can be used to backup data) can be
encrypted using AES-256 and XTEA encryption algorithms
</li><li>The remote JDBC driver supports TCP/IP connections over SSL/TLS
</li><li>The built-in web server supports connections over SSL/TLS
</li><li>Passwords can be sent to the database using char arrays instead of Strings
......@@ -589,11 +594,13 @@ This is achieved using different database URLs. Settings in the URLs are not cas
<br />
<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 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
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 File.createTempFile).
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>.
</p>
......@@ -620,7 +627,7 @@ An example database URL is: <code class="notranslate">jdbc:h2:tcp://localhost/me
</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 ;DB_CLOSE_DELAY=-1 to the database URL.
To keep the database open, add <code class="notranslate">;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>.
</p>
......@@ -687,7 +694,8 @@ if the database files are only accessed by one (and always the same) computer.
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 'FILE_LOCK'.
To open the database with a different file locking method, use the parameter
<code class="notranslate">FILE_LOCK</code>.
The following code opens the database with the 'socket' locking method:
</p>
<pre class="notranslate">
......@@ -729,7 +737,8 @@ 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
SET DB_CLOSE_DELAY &lt;seconds&gt;. The parameter &lt;seconds&gt; specifies the number of seconds to keep
<code class="notranslate">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>
......@@ -780,11 +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 PREFERDOSLIKELINEENDS and IGNOREDRIVERPRIVILEGES are such examples;
The parameters <code class="notranslate">PREFERDOSLIKELINEENDS</code> and
<code class="notranslate">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
;IGNORE_UNKNOWN_SETTINGS=TRUE to the database URL.
<code class="notranslate">;IGNORE_UNKNOWN_SETTINGS=TRUE</code> to the database URL.
</p>
<br />
......@@ -800,13 +810,14 @@ connecting. For a list of supported settings, see <a href="grammar.html">SQL Gra
<br />
<h2 id="custom_access_mode">Custom File Access Mode</h2>
<p>
Usually, the database opens log, data and index files with the access mode 'rw', meaning
read-write (except for read only databases, where the mode 'r' is used).
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).
To open a database in read-only mode if the files are not read-only, use
ACCESS_MODE_DATA=r.
Also supported are 'rws' and 'rwd'.
The access mode used for log files is set via ACCESS_MODE_LOG; for
data and index files use ACCESS_MODE_DATA.
<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>.
These settings must be specified in the database URL:
</p>
<pre class="notranslate">
......@@ -855,11 +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, SELECT statements will generate read locks. This includes subqueries.
Usually, <code class="notranslate">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 SELECT ... FOR UPDATE.
The statements COMMIT and ROLLBACK releases all open locks.
The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks.
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.
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:
......@@ -871,33 +884,34 @@ The following statements generate locks:
</tr>
<tr>
<td>Read</td>
<td>SELECT * FROM TEST;<br />
<td class="notranslate">SELECT * FROM TEST;<br />
CALL SELECT MAX(ID) FROM TEST;<br />
SCRIPT;</td>
</tr>
<tr>
<td>Write</td>
<td>SELECT * FROM TEST WHERE 1=0 FOR UPDATE;</td>
<td class="notranslate">SELECT * FROM TEST WHERE 1=0 FOR UPDATE;</td>
</tr>
<tr>
<td>Write</td>
<td>INSERT INTO TEST VALUES(1, 'Hello');<br />
<td class="notranslate">INSERT INTO TEST VALUES(1, 'Hello');<br />
INSERT INTO TEST SELECT * FROM TEST;<br />
UPDATE TEST SET NAME='Hi';<br />
DELETE FROM TEST;</td>
</tr>
<tr>
<td>Write</td>
<td>ALTER TABLE TEST ...;<br />
<td class="notranslate">ALTER TABLE TEST ...;<br />
CREATE INDEX ... ON TEST ...;<br />
DROP INDEX ...;</td>
</tr>
</table>
<p>
The number of seconds until a lock timeout exception is thrown can be
set separately for each connection using the SQL command SET LOCK_TIMEOUT &lt;milliseconds&gt;.
set separately for each connection using the SQL command
<code class="notranslate">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
SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
<code class="notranslate">SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;</code>. The default lock timeout is persistent.
</p>
<br />
......@@ -912,67 +926,76 @@ If the database trace option is enabled, trace files are created.
The following files can be created by the database:
</p>
<table><tr><th>File Name</th><th>Description</th><th>Number of Files</th></tr>
<tr><td>
<tr><td class="notranslate">
test.h2.db
</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>
</td><td>
1 per database
</td></tr>
<tr><td class="notranslate">
test.data.db
</td><td>
Data file.<br />
Contains the data for all tables.<br />
Format: &lt;database&gt;.data.db
Format: <code class="notranslate">&lt;database&gt;.data.db</code>
</td><td>
1 per database
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.index.db
</td><td>
Index file.<br />
Contains the data for all (b tree) indexes.<br />
Format: &lt;database&gt;.index.db
Format: <code class="notranslate">&lt;database&gt;.index.db</code>
</td><td>
1 per database
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.0.log.db
</td><td>
Transaction log file.<br />
The transaction log is used for recovery.<br />
Format: &lt;database&gt;.&lt;id&gt;.log.db
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.log.db</code>
</td><td>
0 or more per database
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.lock.db
</td><td>
Database lock file.<br />
Exists only while the database is open.<br />
Format: &lt;database&gt;.lock.db
Format: <code class="notranslate">&lt;database&gt;.lock.db</code>
</td><td>
1 per database
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.trace.db
</td><td>
Trace file.<br />
Contains trace information.<br />
Format: &lt;database&gt;.trace.db<br />
If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
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>
</td><td>
1 per database
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.lobs.db/1.t15.lob.db
</td><td>
Large object.<br />
Contains the data for BLOB or CLOB values.<br />
Format: &lt;id&gt;.t&lt;tableId&gt;.lob.db
Format: <code class="notranslate">&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
</td><td>
1 per value
</td></tr>
<tr><td>
<tr><td class="notranslate">
test.123.temp.db
</td><td>
Temporary file.<br />
Contains a temporary blob or a large result set.<br />
Format: &lt;database&gt;.&lt;id&gt;.temp.db
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.temp.db</code>
</td><td>
1 per object
</td></tr>
......@@ -995,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 SCRIPT can be used.
To backup data while the database is running, the SQL command <code class="notranslate">SCRIPT</code> can be used.
</p>
<br />
......@@ -1012,13 +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 CHECKPOINT command.
It is possible to force the log switching by using the <code class="notranslate">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 class="notranslate">;RECOVER=1</code>, as in
<code class="notranslate">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>
......@@ -1031,7 +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
IGNORECASE=TRUE to the database URL (example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code>).
<code class="notranslate">IGNORECASE=TRUE</code> to the database URL
(example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code>).
</p>
<h3>Compatibility Modes</h3>
......@@ -1046,10 +1071,13 @@ Here is the list of currently supported modes and the differences to the regular
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
</li><li>Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY]
as an alternative for LIMIT .. OFFSET.
<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
results in the other value.
</li></ul>
<h3>Derby Compatibility Mode</h3>
......@@ -1057,10 +1085,13 @@ or the SQL statement <code class="notranslate">SET MODE DB2</code>.
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
</li><li>For unique indexes, NULL is distinct. That means only one row with NULL
in one of the columns is allowed.
<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
results in the other value.
</li></ul>
<h3>HSQLDB Compatibility Mode</h3>
......@@ -1068,14 +1099,13 @@ or the SQL statement <code class="notranslate">SET MODE Derby</code>.
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
<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 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>Concatenation with NULL results in NULL. Usually, NULL is treated as an empty
string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
</li><li>For unique indexes, NULL is distinct. That means only one row with NULL
in one of the columns is allowed.
</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></ul>
<h3>MS SQL Server Compatibility Mode</h3>
......@@ -1083,11 +1113,14 @@ or the SQL statement <code class="notranslate">SET MODE HSQLDB</code>.
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
</li><li>Identifiers may be quoted using square brackets as in [Test].
</li><li>For unique indexes, NULL is distinct. That means only one row with NULL
in one of the columns is allowed.
<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
results in the other value.
</li></ul>
<h3>MySQL Compatibility Mode</h3>
......@@ -1095,13 +1128,16 @@ or the SQL statement <code class="notranslate">SET MODE MSSQLServer</code>.
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>.
</p>
<ul><li>When inserting data, if a column is defined to be NOT NULL and NULL is inserted,
<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,
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 CREATE TABLE statement is allowed.
</li><li>Creating indexes in the <code class="notranslate">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
results in the other value.
</li></ul>
<h3>Oracle Compatibility Mode</h3>
......@@ -1109,11 +1145,14 @@ or the SQL statement <code class="notranslate">SET MODE MySQL</code>.
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
</li><li>When using unique indexes, multiple rows with NULL in all columns
are allowed, however it is not allowed to have multiple rows with the
<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>
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
results in the other value.
</li></ul>
<h3>PostgreSQL Compatibility Mode</h3>
......@@ -1121,13 +1160,13 @@ or the SQL statement <code class="notranslate">SET MODE Oracle</code>.
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>.
</p>
<ul><li>For aliased columns, ResultSetMetaData.getColumnName() returns the alias name
and getTableName() returns null.
</li><li>Concatenation with NULL results in NULL. Usually, NULL is treated as an empty
string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
<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 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 'CTID' and 'OID' are supported.
</li><li>The system columns <code class="notranslate">CTID</code> and
<code class="notranslate">OID</code> are supported.
</li></ul>
<br />
......@@ -1140,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 INFORMATION_SCHEMA.SESSION_STATE
The contents of the system table <code class="notranslate">INFORMATION_SCHEMA.SESSION_STATE</code>
contains all client side state that is re-created.
</p>
......@@ -1161,7 +1200,7 @@ 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 .lock.db file and sends the the random key that is stored there to the server).
the client reads <code class="notranslate">.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>
......@@ -1191,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 System.out and/or a file
</li><li>Support for trace levels OFF, ERROR, INFO, and DEBUG
<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><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
......@@ -1201,17 +1240,22 @@ 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 System.out (TRACE_LEVEL_SYSTEM_OUT) tracing,
and one for file tracing (TRACE_LEVEL_FILE).
The trace levels are 0 for OFF, 1 for ERROR (the default), 2 for INFO and 3 for DEBUG.
A database URL with both levels set to DEBUG is:
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>).
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:
</p>
<pre class="notranslate">
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 System.out tracing)
<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).
Example:
</p>
......@@ -1222,10 +1266,11 @@ SET TRACE_LEVEL_SYSTEM_OUT 3
<h3>Setting the Maximum Size of the Trace File</h3>
<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 .old and a new file is created.
If another .old file exists, it is deleted.
The size limit can be changed using the SQL statement
<code class="notranslate">SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code>.
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.
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>.
Example:
</p>
<pre class="notranslate">
......@@ -1234,8 +1279,8 @@ SET TRACE_MAX_FILE_SIZE 1
<h3>Java Code Generation</h3>
<p>
When setting the trace level to INFO or DEBUG, Java source code is generated as well.
This allows to reproduce problems more easily. The trace file looks like this:
When setting the trace level to <code class="notranslate">INFO</code> or <code class="notranslate">DEBUG</code>,
Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this:
</p>
<pre class="notranslate">
...
......@@ -1246,7 +1291,7 @@ This allows to reproduce problems more easily. The trace file looks like this:
...
</pre>
<p>
To filter the Java source code, use the ConvertTraceFile tool as follows:
To filter the Java source code, use the <code class="notranslate">ConvertTraceFile</code> tool as follows:
</p>
<pre class="notranslate">
java -cp h2*.jar org.h2.tools.ConvertTraceFile
......@@ -1264,9 +1309,9 @@ 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 System.out. 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.
written to both file and <code class="notranslate">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>
<p>
<a href="http://www.slf4j.org">SLF4J</a> is a simple facade for various logging APIs
......@@ -1282,9 +1327,10 @@ 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 SET TRACE_LEVEL_FILE 4 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 &lt;database&gt;.trace.db for error messages.
executing the SQL statement <code class="notranslate">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.
</p>
<br />
......@@ -1292,19 +1338,21 @@ If it does not work, check the file &lt;database&gt;.trace.db for error messages
<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 SELECT and CALL statements are allowed.
Only <code class="notranslate">SELECT</code> and <code class="notranslate">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 Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
by calling <code class="notranslate">Connection.isReadOnly()</code>
or by executing the SQL statement <code class="notranslate">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 Backup tool or the BACKUP SQL statement:
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:
</p>
<pre class="notranslate">
BACKUP TO 'data.zip'
......@@ -1331,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
SET DATABASE_EVENT_LISTENER or use a database URL of the form
jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener'
<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>
(the quotes around the class name are required).
See also the DatabaseEventListener API.
See also the <code class="notranslate">DatabaseEventListener</code> API.
</p>
<h3>Opening a Corrupted Database</h3>
......@@ -1448,7 +1496,7 @@ public class Test {
</pre>
<p>
This example requires Java 1.6.
When using Swing, use javax.swing.JPasswordField.
When using Swing, use <code class="notranslate">javax.swing.JPasswordField</code>.
</p>
<h3>Passing the User Name and/or Password in the URL</h3>
......@@ -1485,30 +1533,35 @@ public class Function {
}
</pre>
<p>
The Java function must be registered in the database by calling CREATE ALIAS:
The Java function must be registered in the database by calling <code class="notranslate">CREATE ALIAS</code>:
</p>
<pre class="notranslate">
CREATE ALIAS IS_PRIME FOR "acme.Function.isPrime"
</pre>
<p>
For a complete sample application, see src/test/org/h2/samples/Function.java.
For a complete sample application, see <code class="notranslate">src/test/org/h2/samples/Function.java</code>.
</p>
<h3>Function Data Type Mapping</h3>
<p>
Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL.
Instead, the result of the function is NULL. If the function should be called if a parameter is NULL, you need
to use 'java.lang.Integer' instead of 'int'.
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.
</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: java.lang.Object is mapped to OTHER (a serialized object). Therefore, java.lang.Object can not be used
to match all SQL types (matching all SQL types is not supported). The second special case is Object[]: arrays of any class are mapped to ARRAY.
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>.
</p>
<h3>Functions that require a Connection</h3>
<p>
If the first parameter of a Java function is a java.sql.Connection, then the connection
If the first parameter of a Java function is a <code class="notranslate">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.
......@@ -1516,13 +1569,13 @@ does not need to be (can not be) specified.
<h3>Functions throwing an Exception</h3>
<p>
If a function throws an Exception, then the current statement is rolled back
If a function throws an exception, then the current statement is rolled back
and the exception is thrown to the application.
</p>
<h3>Functions returning a Result Set</h3>
<p>
Functions may returns a result set. Such a function can be called with the CALL statement:
Functions may returns a result set. Such a function can be called with the <code class="notranslate">CALL</code> statement:
</p>
<pre class="notranslate">
public static ResultSet query(Connection conn, String sql) throws SQLException {
......@@ -1592,8 +1645,8 @@ 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 src/test/org/h2/samples/TriggerSample.java.
A Java trigger must implement the interface org.h2.api.Trigger. The trigger class must be available
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
in the classpath of the database engine (when using the server mode, it must be in the classpath
of the server).
</p>
......@@ -1618,14 +1671,14 @@ 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 SQLException.
The trigger can be used to veto a change by throwing a <code class="notranslate">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 .index.db file
To re-build the indexes, the simplest way is to delete the <code class="notranslate">.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:
......@@ -1641,8 +1694,8 @@ public static void compact(String dir, String dbName,
}
</pre>
<p>
See also the sample application org.h2.samples.Compact.
The commands SCRIPT / RUNSCRIPT can be used as well to create a backup
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
of a database and re-build the database from the script.
</p>
......
......@@ -77,7 +77,9 @@ Initial Developer: H2 Group
<br />
<!-- translate
<div id = "google_translate_element"></div>
<a href="http://translate.google.com/translate?u=http%3A%2F%2Fh2database.com"
onclick="javascript:document.getElementById('translate').style.display='';return false;">Translate</a>
<div id = "translate" style="display:none"><div id = "google_translate_element"></div></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
......
......@@ -75,7 +75,7 @@ ${item.syntax}
<br />
<h3 id="information_schema" class="notranslate">Information Schema</h3>
<p>
The system tables in the schema 'INFORMATION_SCHEMA' contain the meta data
The system tables in the schema <code class="notranslate">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>
......
......@@ -56,8 +56,8 @@ JaQu provides full control over when and what SQL statements are executed.
<h3>Restrictions</h3>
<p>
Primitive types (eg. boolean, int, long, double) are not supported. Use
Boolean, Integer, Long, and Double instead.
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.
</p>
<h3>Why in Java?</h3>
......@@ -71,8 +71,8 @@ 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>src/test/org/h2/test/jaqu/* (samples and tests)
</li><li>src/tools/org/h2/jaqu/* (framework)
<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)
</li></ul>
<h2>Building the JaQu library</h2>
......@@ -247,7 +247,7 @@ public class Product implements Table {
}
</pre>
<p>
The method 'define()' contains the mapping definition. It is called once
The method <code class="notranslate">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).
......
......@@ -102,7 +102,7 @@ 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 (SET WRITE_DELAY 1).
and the write delay is 1 second (<code class="notranslate">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:
......@@ -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 derby.system.durability=test) where durability is
Derby supports a testing mode (system property <code class="notranslate">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,8 +135,8 @@ 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 postgresql.conf:
fsync = off, commit_delay = 1000.
The following options where changed in <code class="notranslate">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.
The memory usage number is incorrect, because only the memory usage of the JDBC driver is measured.
......@@ -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 innodb_flush_log_at_trx_commit
(found in the my.ini file) was set to 0. Otherwise (and by default), MySQL is really slow
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
(around 140 statements per second in this test) because it tries to flush the data to disk for each commit.
For small transactions (when autocommit is on) this is really slow.
But many use cases use small or relatively small transactions.
Too bad this setting is not listed in the configuration wizard,
and it always overwritten when using the wizard.
You need to change this setting manually in the file my.ini, and then restart the service.
You need to change this setting manually in the file <code class="notranslate">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>
......@@ -246,8 +246,9 @@ 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 fsync() to flush the buffers, but
most hard drives don't actually flush all data. Calling fsync() slows down transaction commit a lot,
Some databases (for example MySQL) try to enforce this by default by
calling <code class="notranslate">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.
This benchmark switches off autocommit when loading the data, and calls commit after each 1000
......@@ -306,9 +307,11 @@ 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
poleposition-0.20/lib/hsqldb.jar with a newer version (for example hsqldb-1.8.0.7.jar),
<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>),
and then use the setting
hsqldb.connecturl=jdbc:hsqldb:file:data/hsqldb/dbbench2;hsqldb.default_table_type=cached;sql.enforce_size=true in Jdbc.properties.
<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>.
</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>
</li><li>The amount of cache memory is quite important, specially for the PolePosition test.
......@@ -323,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
System.currentTimeMillis(). But this does not work for complex applications with many modules, and for memory problems.
<code class="notranslate">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
......@@ -345,8 +348,8 @@ Ctrl+C (Windows).
<br />
<h2 id="database_profiling">Database Profiling</h2>
<p>
The ConvertTraceFile 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 java -Xrunhprof.
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>.
As an example, execute the the following script using the H2 Console:
</p>
<pre class="notranslate">
......@@ -357,7 +360,7 @@ CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
SET TRACE_LEVEL_FILE 0;
</pre>
<p>
Now convert the .trace.db file using the ConvertTraceFile tool:
Now convert the <code class="notranslate">.trace.db</code> file using the <code class="notranslate">ConvertTraceFile</code> tool:
</p>
<pre class="notranslate">
java -cp h2*.jar org.h2.tools.ConvertTraceFile
......@@ -398,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 .db are not scanned.
Some virus scanners allow to exclude files by suffix. Ensure files ending with <code class="notranslate">.db</code> are not scanned.
</p>
<h3>Using the Trace Options</h3>
......@@ -412,15 +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 SELECT, UPDATE and DELETE statements.
If a column is used in the WHERE clause of a query, and if an index exists on this column,
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,
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 CREATE INDEX statement.
For other columns, indexes need to be created manually using the <code class="notranslate">CREATE INDEX</code> statement.
</p>
<h3>Optimizer</h3>
......@@ -438,33 +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 WHERE clause is always false, then the table is not accessed at all.
If the <code class="notranslate">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 WHERE clause is used, that means it only works for
queries of the form SELECT COUNT(*) FROM table.
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>.
</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 SELECT * FROM TEST T1, TEST T2 WHERE T1.NAME='A' AND T2.ID=T1.ID,
Example: for the query
<code class="notranslate">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 TEST(ID, NAME, FIRSTNAME) and an index on each column,
then two indexes could be used for the query SELECT * FROM TEST WHERE NAME='A' AND FIRSTNAME='B',
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>,
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 ANALYZE can be used to automatically estimate the selectivity of the columns in the tables.
The SQL statement <code class="notranslate">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>
......@@ -481,8 +486,8 @@ 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 (WHERE ID = ?)
but not range scan (WHERE ID &lt; ?). To use hash indexes, use HASH as in:
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>.
</p>
......@@ -503,11 +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 DECIMAL/NUMERIC type is slower and requires more storage than the REAL and DOUBLE types.
<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.
</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 BINARY vs. BLOB and VARCHAR vs. CLOB performance.
</li><li>Parsing and formatting takes longer for the TIME, DATE, and TIMESTAMP types than the numeric types.
</li><li>SMALLINT/TINYINT/BOOLEAN are not significantly smaller or faster to work with than INTEGER in most modes.
</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></ul>
<br />
......@@ -515,10 +526,10 @@ Each data type has different storage and performance characteristics:
<p>
To speed up large imports, consider using the following options temporarily:
</p>
<ul><li>SET CACHE_SIZE (a large cache is faster)
</li><li>SET LOCK_MODE 0 (disable locking)
</li><li>SET LOG 0 (disable the transaction log)
</li><li>SET UNDO_LOG 0 (disable the session undo log)
<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)
</li></ul>
<p>
These options can be set in the database URL:
......
......@@ -76,29 +76,30 @@ 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 http://localhost:8082 .
A browser window should open and point to the Login page at <code class="notranslate">http://localhost:8082</code>.
</td>
</tr>
<tr>
<td>Windows</td>
<td>
Open a file browser, navigate to h2/bin, and double click on h2.bat.<br />
Open a file browser, navigate to <code class="notranslate">h2/bin</code>, and
double click on <code class="notranslate">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: http://localhost:8082).
(URL: <code class="notranslate">http://localhost:8082</code>).
</td>
</tr>
<tr>
<td>Any</td>
<td>
Double click on the h2*.jar file.
This only works if the .jar suffix is associated with java.
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.
</td>
</tr>
<tr>
<td>Any</td>
<td>
Open a console window, navigate to the directory 'h2/bin' and type:
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>
</td>
</tr>
......@@ -145,7 +146,7 @@ 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 .h2.server.properties. This file is stored
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;").
The relevant entry is webPort.
</p>
......@@ -154,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 http://localhost:8082 .
If you started the server on the same computer as the browser, open the URL <code class="notranslate">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:
http://192.168.0.2:8082 .
If you enabled SSL on the server side, the URL needs to start with https:// .
<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>.
</p>
<h3>Multiple Concurrent Sessions</h3>
......@@ -185,11 +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 H2DRIVERS or CLASSPATH. Example (Windows): to add the database driver library
C:\Programs\hsqldb\lib\hsqldb.jar, set the environment variable H2DRIVERS to
C:\Programs\hsqldb\lib\hsqldb.jar.
variables <code class="notranslate">H2DRIVERS</code> or <code class="notranslate">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>.
</p><p>
Multiple drivers can be set; each entry needs to be separated with a ';' (Windows) or ':' (other operating systems).
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).
Spaces in the path names are supported. The settings must not be quoted.
</p>
......@@ -203,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, a 'SELECT * FROM ...' is added as well.
If you click on a table while the query is empty, then <code class="notranslate">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 'SELECT * FROM TEST T WHERE T.' then the table TEST 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.
</p>
<h3>Disconnecting and Stopping the Application</h3>
......@@ -254,7 +258,7 @@ and then opens a connection (using <code class="notranslate">DriverManager.getCo
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 ('sa' for System Administrator in this example). The third parameter is the password.
is the user name (<code class="notranslate">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>
......@@ -338,7 +342,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 -tcpPassword
Shutting down a TCP server can be protected using the option <code class="notranslate">-tcpPassword</code>
(the same password must be used to start and stop the TCP server).
</p>
......@@ -349,8 +353,8 @@ 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 src/tools/org/hibernate/dialect/H2Dialect.java.txt.
You can rename it to H2Dialect.java and include this as a patch in your application.
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.
</p>
<br />
......@@ -398,8 +402,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 shared/lib or
server/lib directory. It is a good idea to open the database when 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
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
......@@ -416,7 +420,8 @@ 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 'context-param' and the 'filter' section):
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):
</p>
<pre class="notranslate">
&lt;listener>
......@@ -424,18 +429,21 @@ add the following snippet to your web.xml file (between the 'context-param' and
&lt;/listener>
</pre>
<p>
For details on how to access the database, see the file DbStarter.java.
By default the DbStarter listener opens an embedded connection
using the database URL 'jdbc:h2:~/test', user name 'sa', and password 'sa'.
For details on how to access the database, see the file <code class="notranslate">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>.
If you want to use this connection within your servlet, you can access as follows:
</p>
<pre class="notranslate">
Connection conn = getServletContext().getAttribute("connection");
</pre>
<p>
The DbStarter can also start the TCP server, however this is disabled by default.
To enable it, use the parameter db.tcpServer in the file web.xml. Here is the complete list of options.
These options need to be placed between the 'description' tag and the 'listener' / 'filter' tags:
<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>.
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:
</p>
<pre class="notranslate">
&lt;context-param>
......@@ -457,14 +465,14 @@ These options need to be placed between the 'description' tag and the 'listener'
</pre>
<p>
When the web application is stopped, the database connection will be closed automatically.
If the TCP server is started within the DbStarter, it will also be stopped automatically.
If the TCP server is started within the <code class="notranslate">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 h2 jar file in your application, and
add the following configuration to your web.xml:
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>:
</p>
<pre class="notranslate">
&lt;servlet&gt;
......@@ -490,13 +498,14 @@ build warConsole
<br />
<h2 id="csv">CSV (Comma Separated Values) Support</h2>
<p>
The CSV file support can be used inside the database using the functions CSVREAD and CSVWRITE,
The CSV file support can be used inside the database using the functions
<code class="notranslate">CSVREAD</code> and <code class="notranslate">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 CSVWRITE can be used to create a CSV file from a query.
The built-in function <code class="notranslate">CSVWRITE</code> can be used to create a CSV file from a query.
Example:
</p>
<pre class="notranslate">
......@@ -507,7 +516,7 @@ 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 CSVREAD. Example:
A CSV file can be read using the function <code class="notranslate">CSVREAD</code>. Example:
</p>
<pre class="notranslate">
SELECT * FROM CSVREAD('test.csv');
......@@ -581,8 +590,8 @@ This can be done using the Script tool:
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 SCRIPT to create the backup of the database.
For more information about the options, see the SQL command SCRIPT.
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>.
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>
......@@ -595,20 +604,20 @@ To restore a database from a SQL script file, you can use the RunScript tool:
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 RUNSCRIPT.
For more information about the options, see the SQL command <code class="notranslate">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 RUNSCRIPT to execute a SQL script.
It is also possible to use the SQL command <code class="notranslate">RUNSCRIPT</code> to execute a SQL script.
SQL script files may contain references to other script files, in the form of
RUNSCRIPT commands. However, when using the server mode, the references script files
<code class="notranslate">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 BACKUP SQL statement and the Backup tool both create a zip file
The <code class="notranslate">BACKUP</code> SQL statement and the Backup 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 BACKUP statement does not lock the
Other than the SCRIPT statement, the <code class="notranslate">BACKUP</code> statement does not lock the
database objects, and therefore does not block other users. The resulting
backup is transactionally consistent:
</p>
......@@ -637,18 +646,18 @@ java -cp h2*.jar org.h2.tools.Backup -?
<p>
The command line tools are:
</p>
<ul><li><b>Backup</b> creates a backup of a database.
</li><li><b>ChangeFileEncryption</b> allows changing the file encryption password or algorithm of a database.
</li><li><b>Console</b> starts the browser based H2 Console.
</li><li><b>ConvertTraceFile</b> converts a .trace.db file to a Java application and SQL script.
</li><li><b>CreateCluster</b> creates a cluster from a standalone database.
</li><li><b>DeleteDbFiles</b> deletes all files belonging to a database.
</li><li><b>Recover</b> helps recovering a corrupted database.
</li><li><b>Restore</b> restores a backup of a database.
</li><li><b>RunScript</b> runs a SQL script against a database.
</li><li><b>Script</b> allows converting a database to a SQL script for backup or migration.
</li><li><b>Server</b> is used in the server mode to start a H2 server.
</li><li><b>Shell</b> is a command line database tool.
<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.
</li></ul>
<p>
The tools can also be called from an application by calling the main or another public method.
......@@ -708,7 +717,8 @@ 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: java.security.AccessControlException: access denied (java.io.FilePermission ... read).
exception will occur: <code class="notranslate">java.security.AccessControlException</code>:
access denied (<code class="notranslate">java.io.FilePermission ... read</code>).
Example permission tags:
</p>
<pre class="notranslate">
......@@ -727,7 +737,7 @@ 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 DriverManager.getConnection(). The build-in connection pool is used as follows:
one using <code class="notranslate">DriverManager.getConnection()</code>.The build-in connection pool is used as follows:
</p>
<pre class="notranslate">
import java.sql.*;
......@@ -782,14 +792,16 @@ SELECT * FROM FT_SEARCH('Hello', 0, 0);
<p>
This will produce a result set that contains the query needed to retrieve the data:
</p>
<p>
<pre class="notranslate">
QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</p>
</pre>
<p>
To get the raw data, use <code class="notranslate">FT_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns SCHEMA (the schema name),
TABLE (the table name), COLUMNS (an array of column names), and KEYS
(an array of objects). To join a table, use a join as in:
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 FT_SEARCH_DATA('Hello', 0, 0) FT, TEST T
WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code>
</p>
......@@ -805,7 +817,8 @@ 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 H2DRIVERS or CLASSPATH.
jar file to the environment variables <code class="notranslate">H2DRIVERS</code> or
<code class="notranslate">CLASSPATH</code>.
To initialize the Lucene fulltext search in a database, call:
</p>
<pre class="notranslate">
......@@ -832,14 +845,15 @@ SELECT * FROM FTL_SEARCH('Hello', 0, 0);
<p>
This will produce a result set that contains the query needed to retrieve the data:
</p>
<p>
<pre class="notranslate">
QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</p>
</pre>
<p>
To get the raw data, use <code class="notranslate">FTL_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns SCHEMA (the schema name),
TABLE (the table name), COLUMNS (an array of column names), and KEYS
(an array of objects). To join a table, use a join as in:
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
WHERE FT.TABLE='TEST' AND T.ID=FT.KEYS[0];</code>
</p>
......@@ -854,7 +868,7 @@ 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 @ and can be used wherever
This database supports user-defined variables. Variables start with <code class="notranslate">@</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>
......@@ -869,7 +883,8 @@ 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 NULL. The data type of a user-defined variable is the data type
Variables that are not set evaluate to <code class="notranslate">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.
</p>
......@@ -887,8 +902,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 SCRIPT command or Script tool, and then load
the database using the RUNSCRIPT command or the RunScript tool in the new time zone.
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.
</p>
<br />
......@@ -906,7 +923,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 class="notranslate">destroy-method</code> will help prevent exceptions on hot-redeployment or when restarting the server.
</p>
<!-- [close] { --></div></td></tr></table><!-- } --><!-- analytics --></body></html>
......
......@@ -3743,7 +3743,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
Connecting to an Embedded (Local) Database
@features_1349_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 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 File.createTempFile). To point to the user home directory, use <code class="notranslate">~/</code> , as in: <code class="notranslate">jdbc:h2:~/test</code> .
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 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> .
@features_1350_h2
Memory-Only Databases
......@@ -3761,7 +3761,7 @@ Sometimes multiple connections to the same memory-only database are required. In
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> .
@features_1355_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 ;DB_CLOSE_DELAY=-1 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> .
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 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> .
@features_1356_h2
Database Files Encryption
......@@ -3806,7 +3806,7 @@ The second method is 'socket' and opens a server socket. The socket method does
It is also possible to open the database without file locking; in this case it is up to the application to protect the database files.
@features_1370_p
To open the database with a different file locking method, use the parameter 'FILE_LOCK'. The following code opens the database with the 'socket' locking method:
To open the database with a different file locking method, use the parameter <code class="notranslate">FILE_LOCK</code> . The following code opens the database with the 'socket' locking method:
@features_1371_p
The following code forces the database to not create a lock file at all. Please note that this is unsafe as another process is able to open the same database, possibly leading to data corruption:
......@@ -3827,7 +3827,7 @@ Closing a Database
Delayed Database Closing
@features_1377_p
Usually, a database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible to keep at least one connection open. The automatic closing of a database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY &lt;seconds&gt;. 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:
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> . The parameter &lt;seconds&gt; specifies the number of seconds to keep a database open after the last connection to it was closed. The following statement will keep a database open for 10 seconds after the last connection was closed:
@features_1378_p
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> .
......@@ -3848,7 +3848,7 @@ Usually, changes to the index file are not logged for performance. If the index
Ignore Unknown Settings
@features_1384_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 PREFERDOSLIKELINEENDS and IGNOREDRIVERPRIVILEGES are such examples; they are simply ignored to improve the compatibility with OpenOffice.org. If an application passes other parameters when connecting to the database, usually the database throws an exception saying the parameter is not supported. It is possible to ignored such parameters by adding ;IGNORE_UNKNOWN_SETTINGS=TRUE to the database URL.
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; 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.
@features_1385_h2
Changing Other Settings when Opening a Connection
......@@ -3860,7 +3860,7 @@ In addition to the settings already described, other database settings can be pa
Custom File Access Mode
@features_1388_p
Usually, the database opens log, data and index files with the access mode 'rw', meaning read-write (except for read only databases, where the mode 'r' is used). To open a database in read-only mode if the files are not read-only, use ACCESS_MODE_DATA=r. Also supported are 'rws' and 'rwd'. The access mode used for log files is set via ACCESS_MODE_LOG; for data and index files use ACCESS_MODE_DATA. These settings must be specified in the database URL:
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). 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> . These settings must be specified in the database URL:
@features_1389_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.
......@@ -3896,7 +3896,7 @@ The database uses table level locks to give each connection a consistent state o
If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If a connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
@features_1400_p
Usually, SELECT 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 SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks:
Usually, <code class="notranslate">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. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks:
@features_1401_th
Type of Lock
......@@ -3950,7 +3950,7 @@ CREATE INDEX ... ON TEST ...;
DROP INDEX ...;
@features_1418_p
The number of seconds until a lock timeout exception is thrown can be set separately for each connection using the SQL command SET LOCK_TIMEOUT &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
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> . 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.
@features_1419_h2
Database File Layout
......@@ -3968,528 +3968,552 @@ Description
Number of Files
@features_1424_td
test.data.db
test.h2.db
@features_1425_td
Data file.
Database file.
@features_1426_td
Contains the data for all tables.
Contains the data and index data for all tables.
@features_1427_td
Format: &lt;database&gt;.data.db
Format: <code class="notranslate">&lt;database&gt;.h2.db</code>
@features_1428_td
1 per database
@features_1429_td
test.index.db
test.data.db
@features_1430_td
Index file.
Data file.
@features_1431_td
Contains the data for all (b tree) indexes.
Contains the data for all tables.
@features_1432_td
Format: &lt;database&gt;.index.db
Format: <code class="notranslate">&lt;database&gt;.data.db</code>
@features_1433_td
1 per database
@features_1434_td
test.0.log.db
test.index.db
@features_1435_td
Transaction log file.
Index file.
@features_1436_td
The transaction log is used for recovery.
Contains the data for all (b tree) indexes.
@features_1437_td
Format: &lt;database&gt;.&lt;id&gt;.log.db
Format: <code class="notranslate">&lt;database&gt;.index.db</code>
@features_1438_td
0 or more per database
1 per database
@features_1439_td
test.lock.db
test.0.log.db
@features_1440_td
Database lock file.
Transaction log file.
@features_1441_td
Exists only while the database is open.
The transaction log is used for recovery.
@features_1442_td
Format: &lt;database&gt;.lock.db
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.log.db</code>
@features_1443_td
1 per database
0 or more per database
@features_1444_td
test.trace.db
test.lock.db
@features_1445_td
Trace file.
Database lock file.
@features_1446_td
Contains trace information.
Exists only while the database is open.
@features_1447_td
Format: &lt;database&gt;.trace.db
Format: <code class="notranslate">&lt;database&gt;.lock.db</code>
@features_1448_td
If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
1 per database
@features_1449_td
1 per database
test.trace.db
@features_1450_td
test.lobs.db/1.t15.lob.db
Trace file.
@features_1451_td
Large object.
Contains trace information.
@features_1452_td
Contains the data for BLOB or CLOB values.
Format: <code class="notranslate">&lt;database&gt;.trace.db</code>
@features_1453_td
Format: &lt;id&gt;.t&lt;tableId&gt;.lob.db
If the file is too big, it is renamed to <code class="notranslate">&lt;database&gt;.trace.db.old</code>
@features_1454_td
1 per value
1 per database
@features_1455_td
test.123.temp.db
test.lobs.db/1.t15.lob.db
@features_1456_td
Temporary file.
Large object.
@features_1457_td
Contains a temporary blob or a large result set.
Contains the data for BLOB or CLOB values.
@features_1458_td
Format: &lt;database&gt;.&lt;id&gt;.temp.db
Format: <code class="notranslate">&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
@features_1459_td
1 per value
@features_1460_td
test.123.temp.db
@features_1461_td
Temporary file.
@features_1462_td
Contains a temporary blob or a large result set.
@features_1463_td
Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.temp.db</code>
@features_1464_td
1 per object
@features_1460_h3
@features_1465_h3
Moving and Renaming Database Files
@features_1461_p
@features_1466_p
Database name and location are not stored inside the database files.
@features_1462_p
@features_1467_p
While a database is closed, the files can be moved to another directory, and they can be renamed as well (as long as all files start with the same name).
@features_1463_p
@features_1468_p
As there is no platform specific data in the files, they can be moved to other operating systems without problems.
@features_1464_h3
@features_1469_h3
Backup
@features_1465_p
@features_1470_p
When the database is closed, it is possible to backup the database files. Please note that index files do not need to be backed up, because they contain redundant data, and will be recreated automatically if they don't exist.
@features_1466_p
To backup data while the database is running, the SQL command SCRIPT can be used.
@features_1471_p
To backup data while the database is running, the SQL command <code class="notranslate">SCRIPT</code> can be used.
@features_1467_h2
@features_1472_h2
Logging and Recovery
@features_1468_p
@features_1473_p
Whenever data is modified in the database and those changes are committed, the changes are logged to disk (except for in-memory objects). The changes to the data file itself are usually written later on, to optimize disk access. If there is a power failure, the data and index files are not up-to-date. But because the changes are in the log file, the next time the database is opened, the changes that are in the log file are re-applied automatically.
@features_1469_p
@features_1474_p
Please note that index file updates are not logged by default. If the database is opened and recovery is required, the index file is rebuilt from scratch.
@features_1470_p
There is usually only one log file per database. This file grows until the database is closed successfully, and is then deleted. Or, if the file gets too big, the database switches to another log file (with a higher id). It is possible to force the log switching by using the CHECKPOINT command.
@features_1475_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.
@features_1471_p
@features_1476_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 the summary (object allocation table) is not read in this case, so opening the database takes longer.
@features_1472_h2
@features_1477_h2
Compatibility
@features_1473_p
@features_1478_p
All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however:
@features_1474_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 IGNORECASE=TRUE to the database URL (example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code> ).
@features_1479_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> ).
@features_1475_h3
@features_1480_h3
Compatibility Modes
@features_1476_p
@features_1481_p
For certain features, this database can emulate the behavior of specific databases. Not all features or differences of those databases are implemented. Here is the list of currently supported modes and the differences to the regular mode:
@features_1477_h3
@features_1482_h3
DB2 Compatibility Mode
@features_1478_p
@features_1483_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> .
@features_1479_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1484_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> .
@features_1485_li
Support for the syntax <code class="notranslate">[OFFSET .. ROW] [FETCH ... ONLY]</code> as an alternative for <code class="notranslate">LIMIT .. OFFSET</code> .
@features_1480_li
Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative for LIMIT .. OFFSET.
@features_1486_li
Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1481_h3
@features_1487_h3
Derby Compatibility Mode
@features_1482_p
@features_1488_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> .
@features_1483_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1489_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> .
@features_1484_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1490_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.
@features_1491_li
Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1485_h3
@features_1492_h3
HSQLDB Compatibility Mode
@features_1486_p
@features_1493_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> .
@features_1487_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1494_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> .
@features_1488_li
@features_1495_li
When converting the scale of decimal data, the number is only converted if the new scale is smaller than the current scale. Usually, the scale is converted and 0s are added if required.
@features_1489_li
Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
@features_1490_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1496_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.
@features_1491_h3
@features_1497_h3
MS SQL Server Compatibility Mode
@features_1492_p
@features_1498_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> .
@features_1493_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1499_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> .
@features_1494_li
Identifiers may be quoted using square brackets as in [Test].
@features_1500_li
Identifiers may be quoted using square brackets as in <code class="notranslate">[Test]</code> .
@features_1495_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1501_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.
@features_1502_li
Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1496_h3
@features_1503_h3
MySQL Compatibility Mode
@features_1497_p
@features_1504_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> .
@features_1498_li
When inserting data, if a column is defined to be NOT NULL and NULL is inserted, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
@features_1505_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, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
@features_1499_li
Creating indexes in the CREATE TABLE statement is allowed.
@features_1506_li
Creating indexes in the <code class="notranslate">CREATE TABLE</code> statement is allowed.
@features_1500_li
@features_1507_li
Meta data calls return identifiers in lower case.
@features_1501_li
@features_1508_li
When converting a floating point number to an integer, the fractional digits are not truncated, but the value is rounded.
@features_1502_h3
@features_1509_li
Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1510_h3
Oracle Compatibility Mode
@features_1503_p
@features_1511_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> .
@features_1504_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1512_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> .
@features_1505_li
When using unique indexes, multiple rows with NULL in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
@features_1513_li
When using unique indexes, multiple rows with <code class="notranslate">NULL</code> in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
@features_1514_li
Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1506_h3
@features_1515_h3
PostgreSQL Compatibility Mode
@features_1507_p
@features_1516_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> .
@features_1508_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1509_li
Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
@features_1517_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> .
@features_1510_li
@features_1518_li
When converting a floating point number to an integer, the fractional digits are not be truncated, but the value is rounded.
@features_1511_li
The system columns 'CTID' and 'OID' are supported.
@features_1519_li
The system columns <code class="notranslate">CTID</code> and <code class="notranslate">OID</code> are supported.
@features_1512_h2
@features_1520_h2
Auto-Reconnect
@features_1513_p
@features_1521_p
The auto-reconnect feature causes the JDBC driver to reconnect to the database if the connection is lost. The automatic re-connect only occurs when auto-commit is enabled; if auto-commit is disabled, an exception is thrown.
@features_1514_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 INFORMATION_SCHEMA.SESSION_STATE contains all client side state that is re-created.
@features_1522_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> contains all client side state that is re-created.
@features_1515_h2
@features_1523_h2
Automatic Mixed Mode
@features_1516_p
@features_1524_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. You can use the same database URL no matter if the database is already open or not.
@features_1517_p
@features_1525_p
When using this mode, the first connection to the database is made in embedded mode, and additionally a server is started internally. If the database is already open in another process, the server mode is used automatically.
@features_1518_p
The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads .lock.db file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
@features_1526_p
The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads <code class="notranslate">.lock.db</code> file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
@features_1519_p
@features_1527_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. This mode is not supported for in-memory databases.
@features_1520_p
@features_1528_p
Here is an example how to use this mode. Application 1 and 2 are not necessarily started on the same computer, but they need to have access to the database files. Application 1 and 2 are typically two different processes (however they could run within the same process).
@features_1521_h2
@features_1529_h2
Using the Trace Options
@features_1522_p
@features_1530_p
To find problems in an application, it is sometimes good to see what database operations where executed. This database offers the following trace features:
@features_1523_li
Trace to System.out and/or a file
@features_1531_li
Trace to <code class="notranslate">System.out</code> and/or to a file
@features_1524_li
Support for trace levels OFF, ERROR, INFO, and DEBUG
@features_1532_li
Support for trace levels <code class="notranslate">OFF, ERROR, INFO, DEBUG</code>
@features_1525_li
@features_1533_li
The maximum size of the trace file can be set
@features_1526_li
@features_1534_li
It is possible to generate Java source code from the trace file
@features_1527_li
@features_1535_li
Trace can be enabled at runtime by manually creating a file
@features_1528_h3
@features_1536_h3
Trace Options
@features_1529_p
The simplest way to enable the trace option is setting it in the database URL. There are two settings, one for System.out (TRACE_LEVEL_SYSTEM_OUT) tracing, and one for file tracing (TRACE_LEVEL_FILE). The trace levels are 0 for OFF, 1 for ERROR (the default), 2 for INFO and 3 for DEBUG. A database URL with both levels set to DEBUG is:
@features_1537_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> ). 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:
@features_1530_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 System.out tracing) or <code class="notranslate">SET TRACE_LEVEL_FILE level</code> (for file tracing). Example:
@features_1538_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). Example:
@features_1531_h3
@features_1539_h3
Setting the Maximum Size of the Trace File
@features_1532_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 .old and a new file is created. If another .old file exists, it is deleted. The size limit can be changed using the SQL statement <code class="notranslate">SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . Example:
@features_1540_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. 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> . Example:
@features_1533_h3
@features_1541_h3
Java Code Generation
@features_1534_p
When setting the trace level to INFO or DEBUG, Java source code is generated as well. This allows to reproduce problems more easily. The trace file looks like this:
@features_1542_p
When setting the trace level to <code class="notranslate">INFO</code> or <code class="notranslate">DEBUG</code> , Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this:
@features_1535_p
To filter the Java source code, use the ConvertTraceFile tool as follows:
@features_1543_p
To filter the Java source code, use the <code class="notranslate">ConvertTraceFile</code> tool as follows:
@features_1536_p
@features_1544_p
The generated file <code class="notranslate">Test.java</code> will contain the Java source code. The generated source code may be too large to compile (the size of a Java method is limited). If this is the case, the source code needs to be split in multiple methods. The password is not listed in the trace file and therefore not included in the source code.
@features_1537_h2
@features_1545_h2
Using Other Logging APIs
@features_1538_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 System.out. In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
@features_1546_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> . In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
@features_1539_a
@features_1547_a
SLF4J
@features_1540_p
@features_1548_p
is a simple facade for various logging APIs and allows to plug in the desired implementation at deployment time. SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), Java logging, x4juli, and Simple Log.
@features_1541_p
@features_1549_p
To enable SLF4J, set the file trace level to 4 in the database URL:
@features_1542_p
Changing the log mechanism is not possible after the database is open, that means executing the SQL statement SET TRACE_LEVEL_FILE 4 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 &lt;database&gt;.trace.db for error messages.
@features_1550_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> 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.
@features_1543_h2
@features_1551_h2
Read Only Databases
@features_1544_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 SELECT and CALL 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 Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
@features_1552_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. 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> .
@features_1545_h2
@features_1553_h2
Read Only Databases in Zip or Jar File
@features_1546_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 Backup tool or the BACKUP SQL statement:
@features_1554_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:
@features_1547_p
@features_1555_p
The database must not have pending changes, that means you need to close all connections to the database, open one single connection, and then execute the statement. Afterwards, you can log out, and directly open the database in the zip file using the following database URL:
@features_1548_p
@features_1556_p
Databases in zip files are read-only. The performance for some queries will be slower than when using a regular database, because random access in zip files is not supported (only streaming). How much this affects the performance depends on the queries and the data. The database is not read in memory; therefore large databases are supported as well. The same indexes are used as when using a regular database.
@features_1549_h2
@features_1557_h2
Graceful Handling of Low Disk Space Situations
@features_1550_p
If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement SET DATABASE_EVENT_LISTENER or use a database URL of the form jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener' (the quotes around the class name are required). See also the DatabaseEventListener API.
@features_1558_p
If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement <code 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> (the quotes around the class name are required). See also the <code class="notranslate">DatabaseEventListener</code> API.
@features_1551_h3
@features_1559_h3
Opening a Corrupted Database
@features_1552_p
@features_1560_p
If a database cannot be opened because the boot info (the SQL script that is run at startup) is corrupted, then the database can be opened by specifying a database event listener. The exceptions are logged, but opening the database will continue.
@features_1553_h2
@features_1561_h2
Computed Columns / Function Based Index
@features_1554_p
@features_1562_p
Function indexes are not directly supported by this database, but they can be emulated by using computed columns. For example, if an index on the upper-case version of a column is required, create a computed column with the upper-case version of the original column, and create an index for this column:
@features_1555_p
@features_1563_p
When inserting data, it is not required (and not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table:
@features_1556_h2
@features_1564_h2
Multi-Dimensional Indexes
@features_1557_p
@features_1565_p
A tool is provided to execute efficient multi-dimension (spatial) range queries. This database does not support a specialized spatial index (R-Tree or similar). Instead, the B-Tree index is used. For each record, the multi-dimensional key is converted (mapped) to a single dimensional (scalar) value. This value specifies the location on a space-filling curve.
@features_1558_p
@features_1566_p
Currently, Z-order (also called N-order or Morton-order) is used; Hilbert curve could also be used, but the implementation is more complex. The algorithm to convert the multi-dimensional value is called bit-interleaving. The scalar value is indexed using a B-Tree index (usually using a computed column).
@features_1559_p
@features_1567_p
The method can result in a drastic performance improvement over just using an index on the first column. Depending on the data and number of dimensions, the improvement is usually higher than factor 5. The tool generates a SQL query from a specified multi-dimensional range. The method used is not database dependent, and the tool can easily be ported to other databases. For an example how to use the tool, please have a look at the sample code provided in TestMultiDimension.java.
@features_1560_h2
@features_1568_h2
Using Passwords
@features_1561_h3
@features_1569_h3
Using Secure Passwords
@features_1562_p
@features_1570_p
Remember that weak passwords can be broken no matter of the encryption and security protocol. Don't use passwords that can be found in a dictionary. Also appending numbers does not make them secure. A way to create good passwords that can be remembered is, take the first letters of a sentence, use upper and lower case characters, and creatively include special characters. Example:
@features_1563_p
@features_1571_p
i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
@features_1564_h3
@features_1572_h3
Passwords: Using Char Arrays instead of Strings
@features_1565_p
@features_1573_p
Java Strings are immutable objects and cannot be safely 'destroyed' by the application. After creating a String, it will remain in the main memory of the computer at least until it is garbage collected. The garbage collection cannot be controlled by the application, and even if it is garbage collected the data may still remain in memory. It might also be possible that the part of memory containing the password is swapped to disk (because not enough main memory is available).
@features_1566_p
@features_1574_p
An attacker might have access to the swap file of the operating system. It is therefore a good idea to use char arrays instead of Strings to store passwords. Char arrays can be cleared (filled with zeros) after use, and therefore the password will not be stored in the swap file.
@features_1567_p
@features_1575_p
This database supports using char arrays instead of String to pass user and file passwords. The following code can be used to do that:
@features_1568_p
This example requires Java 1.6. When using Swing, use javax.swing.JPasswordField.
@features_1576_p
This example requires Java 1.6. When using Swing, use <code class="notranslate">javax.swing.JPasswordField</code> .
@features_1569_h3
@features_1577_h3
Passing the User Name and/or Password in the URL
@features_1570_p
@features_1578_p
Instead of passing the user name as a separate parameter as in <code class="notranslate">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">Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter.
@features_1571_h2
@features_1579_h2
User-Defined Functions and Stored Procedures
@features_1572_p
@features_1580_p
In addition to the built-in functions, this database supports user-defined Java functions. In this database, Java functions can be used as stored procedures as well. A function must be declared (registered) before it can be used. Only static Java methods are supported; both the class and the method must be public. Example Java method:
@features_1573_p
The Java function must be registered in the database by calling CREATE ALIAS:
@features_1581_p
The Java function must be registered in the database by calling <code class="notranslate">CREATE ALIAS</code> :
@features_1574_p
For a complete sample application, see src/test/org/h2/samples/Function.java.
@features_1582_p
For a complete sample application, see <code class="notranslate">src/test/org/h2/samples/Function.java</code> .
@features_1575_h3
@features_1583_h3
Function Data Type Mapping
@features_1576_p
Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. Instead, the result of the function is NULL. If the function should be called if a parameter is NULL, you need to use 'java.lang.Integer' instead of 'int'.
@features_1584_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.
@features_1577_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: java.lang.Object is mapped to OTHER (a serialized object). Therefore, java.lang.Object can not be used to match all SQL types (matching all SQL types is not supported). The second special case is Object[]: arrays of any class are mapped to ARRAY.
@features_1585_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> .
@features_1578_h3
@features_1586_h3
Functions that require a Connection
@features_1579_p
If the first parameter of a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
@features_1587_p
If the first parameter of a Java function is a <code class="notranslate">java.sql.Connection</code> , then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
@features_1580_h3
@features_1588_h3
Functions throwing an Exception
@features_1581_p
If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
@features_1589_p
If a function throws an exception, then the current statement is rolled back and the exception is thrown to the application.
@features_1582_h3
@features_1590_h3
Functions returning a Result Set
@features_1583_p
Functions may returns a result set. Such a function can be called with the CALL statement:
@features_1591_p
Functions may returns a result set. Such a function can be called with the <code class="notranslate">CALL</code> statement:
@features_1584_h3
@features_1592_h3
Using SimpleResultSet
@features_1585_p
@features_1593_p
A function can create a result set using the SimpleResultSet tool:
@features_1586_h3
@features_1594_h3
Using a Function as a Table
@features_1587_p
@features_1595_p
A function that returns a result set can be used like a table. However, in this case the function is called at least twice: first while parsing the statement to collect the column names (with parameters set to null 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> .
@features_1588_h2
@features_1596_h2
Triggers
@features_1589_p
This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see src/test/org/h2/samples/TriggerSample.java. A Java trigger must implement the interface org.h2.api.Trigger. The trigger class must be available in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
@features_1597_p
This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see <code 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 in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
@features_1590_p
@features_1598_p
The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database:
@features_1591_p
The trigger can be used to veto a change, by throwing a SQLException.
@features_1599_p
The trigger can be used to veto a change by throwing a <code class="notranslate">SQLException</code> .
@features_1592_h2
@features_1600_h2
Compacting a Database
@features_1593_p
Empty space in the database file is re-used automatically. To re-build the indexes, the simplest way is to delete the .index.db file while the database is closed. However in some situations (for example after deleting a lot of data in a database), one sometimes wants to shrink the size of the database (compact a database). Here is a sample function to do this:
@features_1601_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 while the database is closed. However in some situations (for example after deleting a lot of data in a database), one sometimes wants to shrink the size of the database (compact a database). Here is a sample function to do this:
@features_1594_p
See also the sample application org.h2.samples.Compact. The commands SCRIPT / RUNSCRIPT can be used as well to create a backup of a database and re-build the database from the script.
@features_1602_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 of a database and re-build the database from the script.
@features_1595_h2
@features_1603_h2
Cache Settings
@features_1596_p
@features_1604_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> .
@features_1597_p
@features_1605_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> .
@features_1598_p
@features_1606_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 is listed for the data and index file.
@fragments_1000_b
......@@ -4901,7 +4925,7 @@ JaQu does not require or contain any data caching mechanism. Like JDBC and iBati
Restrictions
@jaqu_1009_p
Primitive types (eg. boolean, int, long, double) are not supported. Use Boolean, Integer, Long, and Double instead.
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.
@jaqu_1010_h3
Why in Java?
......@@ -4915,91 +4939,97 @@ Current State
@jaqu_1013_p
Currently, JaQu is only tested with the H2 database. The API may change in future versions. JaQu is not part of the h2 jar file, however the source code is included in H2, under:
@jaqu_1014_li
src/test/org/h2/test/jaqu/* (samples and tests)
@jaqu_1014_code
src/test/org/h2/test/jaqu/*
@jaqu_1015_li
src/tools/org/h2/jaqu/* (framework)
(samples and tests)
@jaqu_1016_h2
@jaqu_1016_code
src/tools/org/h2/jaqu/*
@jaqu_1017_li
(framework)
@jaqu_1018_h2
Building the JaQu library
@jaqu_1017_p
@jaqu_1019_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> .
@jaqu_1018_h2
@jaqu_1020_h2
Requirements
@jaqu_1019_p
@jaqu_1021_p
JaQu requires Java 1.5. Annotations are not need. Currently, JaQu is only tested with the H2 database engine, however in theory it should work with any database that supports the JDBC API.
@jaqu_1020_h2
@jaqu_1022_h2
Example Code
@jaqu_1021_h2
@jaqu_1023_h2
Configuration
@jaqu_1022_p
@jaqu_1024_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. Example:
@jaqu_1023_p
The method 'define()' 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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
@jaqu_1025_p
The method <code class="notranslate">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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
@jaqu_1024_h2
@jaqu_1026_h2
Natural Syntax
@jaqu_1025_p
@jaqu_1027_p
The plan is to support more natural (pure Java) syntax in conditions. 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:
@jaqu_1026_h2
@jaqu_1028_h2
Other Ideas
@jaqu_1027_p
@jaqu_1029_p
This project has just been started, and nothing is fixed yet. Some ideas for what to implement are:
@jaqu_1028_li
@jaqu_1030_li
Support queries on collections (instead of using a database).
@jaqu_1029_li
@jaqu_1031_li
Provide API level compatibility with JPA (so that JaQu can be used as an extension of JPA).
@jaqu_1030_li
@jaqu_1032_li
Internally use a JPA implementation (for example Hibernate) instead of SQL directly.
@jaqu_1031_li
@jaqu_1033_li
Use PreparedStatements and cache them.
@jaqu_1032_h2
@jaqu_1034_h2
Related Projects
@jaqu_1033_a
@jaqu_1035_a
Dreamsource ORM
@jaqu_1034_a
@jaqu_1036_a
Empire-db
@jaqu_1035_a
@jaqu_1037_a
JEQUEL: Java Embedded QUEry Language
@jaqu_1036_a
@jaqu_1038_a
Joist
@jaqu_1037_a
@jaqu_1039_a
JoSQL
@jaqu_1038_a
@jaqu_1040_a
LIQUidFORM
@jaqu_1039_a
@jaqu_1041_a
Quaere (Alias implementation)
@jaqu_1040_a
@jaqu_1042_a
Quaere
@jaqu_1041_a
@jaqu_1043_a
Querydsl
@jaqu_1042_a
@jaqu_1044_a
Squill
@license_1000_h1
......
......@@ -2843,7 +2843,7 @@ Javaで記載
コストベースオプティマイザ、複雑なクエリーのために遺伝的アルゴリズムを使用、zero-administration
@features_1049_li
スクロール可能result setと更新可能result setをサポート、大きなresult set、外部結果ソート、 関数はresult setを返す
#Scrollable and updatable result set support, large result set, external result sorting, functions can return a result set
@features_1050_li
暗号化されたデータベース (AES または XTEA), SHA-256 パスワード暗号化、暗号化関数、SSL
......@@ -3743,7 +3743,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
エンベッド (ローカル) データベースに接続
@features_1349_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 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 File.createTempFile). To point to the user home directory, use <code class="notranslate">~/</code> , as in: <code class="notranslate">jdbc:h2:~/test</code> .
#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 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> .
@features_1350_h2
メモリオンリーデータベース
......@@ -3761,7 +3761,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
#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> .
@features_1355_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 ;DB_CLOSE_DELAY=-1 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> .
#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 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> .
@features_1356_h2
#Database Files Encryption
......@@ -3806,7 +3806,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
ファイルロッキングなしでデータベースを開始することも可能です; このケースでは、データベースファイルを保護するのはアプリケーション次第です。
@features_1370_p
異なったファイルロックメソッドでデータベースを開くには、"FILE_LOCK" パラメータを使用します。以下のコードは "socket" ロックメソッドのデータベースを開きます:
#To open the database with a different file locking method, use the parameter <code class="notranslate">FILE_LOCK</code> . The following code opens the database with the 'socket' locking method:
@features_1371_p
以下のコードは、データベースにロックファイルを全く作らないよう強要させます。これは、データ破損を導く可能性のある、同じデータベースを開くことができる他のプロセスのように、安全ではないということに注意して下さい:
......@@ -3827,7 +3827,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
データベースの遅延終了
@features_1377_p
#Usually, a database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible to keep at least one connection open. The automatic closing of a database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY &lt;seconds&gt;. 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:
#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> . The parameter &lt;seconds&gt; specifies the number of seconds to keep a database open after the last connection to it was closed. The following statement will keep a database open for 10 seconds after the last connection was closed:
@features_1378_p
#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> .
......@@ -3848,7 +3848,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
未知の設定を無視
@features_1384_p
データベースに接続する時、いくつかのアプリケーションが (例えば、OpenOffice.org Base) いくつかの追加パラメータを渡します。なぜそれらのパラメータが渡されるのかは知られていません。PREFERDOSLIKELINEENDS と IGNOREDRIVERPRIVILEGES はパラメータの例で、それらは、OpenOffice.orgとの互換性を改良するために単に無視されます。もしデータベースに接続する時、アプリケーションが他のパラメータを渡していたら、通常データベースは、 パラメータはサポートされていません、という例外を投げます。データベースURLに ;IGNORE_UNKNOWN_SETTINGS=TRUE を追加することで、このようなパラメータを無視することが可能です。
#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; 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.
@features_1385_h2
接続が開始された時に他の設定を変更する
......@@ -3860,7 +3860,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
カスタムファイル アクセスモード
@features_1388_p
#Usually, the database opens log, data and index files with the access mode 'rw', meaning read-write (except for read only databases, where the mode 'r' is used). To open a database in read-only mode if the files are not read-only, use ACCESS_MODE_DATA=r. Also supported are 'rws' and 'rwd'. The access mode used for log files is set via ACCESS_MODE_LOG; for data and index files use ACCESS_MODE_DATA. These settings must be specified in the database URL:
#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). 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> . These settings must be specified in the database URL:
@features_1389_p
詳細は <a href="advanced.html#durability_problems">永続性問題</a> をご覧下さい。 多くのオペレーティングシステムでは、アクセスモード "rws" において、データがディスクに書かれていることを保証しません。
......@@ -3896,7 +3896,7 @@ jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
#If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If a connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
@features_1400_p
#Usually, SELECT 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 SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks:
#Usually, <code class="notranslate">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. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks:
@features_1401_th
ロックの種類
......@@ -3950,7 +3950,7 @@ Write
#DROP INDEX ...;
@features_1418_p
SQLコマンド SET LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、ロックタイムアウトの例外が投げられるまでの秒数を、それぞれの接続ごとに別々に設定することができます。SQLコマンド SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、初期のロックタイムアウト (新しい接続に使用されるタイムアウト) を設定することができます。デフォルトのロックタイムアウトは永続的です。
#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> . 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.
@features_1419_h2
データベースファイルレイアウト
......@@ -3968,528 +3968,552 @@ SQLコマンド SET LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、ロッ
ファイル数
@features_1424_td
test.data.db
#test.h2.db
@features_1425_td
#Data file.
#Database file.
@features_1426_td
#Contains the data for all tables.
#Contains the data and index data for all tables.
@features_1427_td
フォーマット: &lt;database&gt;.data.db
#Format: <code class="notranslate">&lt;database&gt;.h2.db</code>
@features_1428_td
データベースごとに1ファイル
@features_1429_td
test.index.db
test.data.db
@features_1430_td
#Index file.
#Data file.
@features_1431_td
#Contains the data for all (b tree) indexes.
#Contains the data for all tables.
@features_1432_td
フォーマット: &lt;database&gt;.index.db
#Format: <code class="notranslate">&lt;database&gt;.data.db</code>
@features_1433_td
データベースごとに1ファイル
@features_1434_td
test.0.log.db
test.index.db
@features_1435_td
#Transaction log file.
#Index file.
@features_1436_td
#The transaction log is used for recovery.
#Contains the data for all (b tree) indexes.
@features_1437_td
フォーマット: &lt;database&gt;.&lt;id&gt;.log.db
#Format: <code class="notranslate">&lt;database&gt;.index.db</code>
@features_1438_td
データベースごとに0ファイル以上
データベースごとに1ファイル
@features_1439_td
test.lock.db
test.0.log.db
@features_1440_td
#Database lock file.
#Transaction log file.
@features_1441_td
#Exists only while the database is open.
#The transaction log is used for recovery.
@features_1442_td
フォーマット: &lt;database&gt;.lock.db
#Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.log.db</code>
@features_1443_td
データベースごとに1ファイル
データベースごとに0ファイル以上
@features_1444_td
test.trace.db
test.lock.db
@features_1445_td
#Trace file.
#Database lock file.
@features_1446_td
#Contains trace information.
#Exists only while the database is open.
@features_1447_td
フォーマット: &lt;database&gt;.trace.db
#Format: <code class="notranslate">&lt;database&gt;.lock.db</code>
@features_1448_td
ファイルが大きすぎる場合、&lt;database&gt;.trace.db.old に改名される
データベースごとに1ファイル
@features_1449_td
データベースごとに1ファイル
test.trace.db
@features_1450_td
#test.lobs.db/1.t15.lob.db
#Trace file.
@features_1451_td
#Large object.
#Contains trace information.
@features_1452_td
#Contains the data for BLOB or CLOB values.
#Format: <code class="notranslate">&lt;database&gt;.trace.db</code>
@features_1453_td
#Format: &lt;id&gt;.t&lt;tableId&gt;.lob.db
#If the file is too big, it is renamed to <code class="notranslate">&lt;database&gt;.trace.db.old</code>
@features_1454_td
#1 per value
データベースごとに1ファイル
@features_1455_td
test.123.temp.db
#test.lobs.db/1.t15.lob.db
@features_1456_td
#Temporary file.
#Large object.
@features_1457_td
#Contains a temporary blob or a large result set.
#Contains the data for BLOB or CLOB values.
@features_1458_td
#Format: &lt;database&gt;.&lt;id&gt;.temp.db
#Format: <code class="notranslate">&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
@features_1459_td
#1 per value
@features_1460_td
test.123.temp.db
@features_1461_td
#Temporary file.
@features_1462_td
#Contains a temporary blob or a large result set.
@features_1463_td
#Format: <code class="notranslate">&lt;database&gt;.&lt;id&gt;.temp.db</code>
@features_1464_td
オブジェクトごとに1ファイル
@features_1460_h3
@features_1465_h3
データベースファイルの移動と改名
@features_1461_p
@features_1466_p
#Database name and location are not stored inside the database files.
@features_1462_p
@features_1467_p
データベースが閉じられている間、ファイルは他のディレクトリに移動することができ、同様にファイル名を変えることもできます (全てのファイルが同じ名前で始まる必要があります)。
@features_1463_p
@features_1468_p
ファイルにはプラットホーム固有のデータがないので、問題なく他のオペレーティングシステムに移動することができます。
@features_1464_h3
@features_1469_h3
バックアップ
@features_1465_p
@features_1470_p
データベースが閉じられている時、データベースファイルのバックアップをとることが可能です。インデックスファイルはバックアップをとる必要はありません。なぜなら、インデックスファイルは冗長なデータを含み、もしファイルが存在しなければ自動的に再作成されるからです。
@features_1466_p
データベースが動作している間にバックアップデータをとるために、SQLコマンド SCRIPTを使うことができます。
@features_1471_p
#To backup data while the database is running, the SQL command <code class="notranslate">SCRIPT</code> can be used.
@features_1467_h2
@features_1472_h2
ログとリカバリー
@features_1468_p
@features_1473_p
データベースでデータが修正され、それらの変更がコミットされた時はいつでも、変更はディスクに記録されます (インメモリオブジェクトを除いて)。データファイル自体への変更は通常、ディスクアクセスを最適化するために後で書かれています。もし電源異常があった場合、データファイルとインデックスファイルはアップデートされません。しかし、変更がログファイルに書かれていれば、次回データベースを開いた時に、ログファイルに書かれた変更は自動的に再び適用されます。
@features_1469_p
@features_1474_p
インデックスファイルのアップデートはデフォルトでは記録されないことに注意して下さい。もしデータベースが開かれて、リカバリーが必要だとされたら、インデックスファイルは最初から作り替えられます。
@features_1470_p
通常、データベースごとにたったひとつのログファイルがあります。このファイルは、データベースが正常に終了されるまで増大し、削除されます。また、ファイルが大きくなりすぎたら、データベースは別のログファイルに交換します (より大きなIDで)。CHECKPOINT コマンドを使用することによって、ログの切り替えを強制することが可能です。
@features_1475_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.
@features_1471_p
@features_1476_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 the summary (object allocation table) is not read in this case, so opening the database takes longer.
@features_1472_h2
@features_1477_h2
互換性
@features_1473_p
@features_1478_p
#All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however:
@features_1474_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 IGNORECASE=TRUE to the database URL (example: <code class="notranslate">jdbc:h2:~/test;IGNORECASE=TRUE</code> ).
@features_1479_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> ).
@features_1475_h3
@features_1480_h3
互換モード
@features_1476_p
@features_1481_p
#For certain features, this database can emulate the behavior of specific databases. Not all features or differences of those databases are implemented. Here is the list of currently supported modes and the differences to the regular mode:
@features_1477_h3
@features_1482_h3
#DB2 Compatibility Mode
@features_1478_p
@features_1483_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> .
@features_1479_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1484_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> .
@features_1485_li
#Support for the syntax <code class="notranslate">[OFFSET .. ROW] [FETCH ... ONLY]</code> as an alternative for <code class="notranslate">LIMIT .. OFFSET</code> .
@features_1480_li
#Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative for LIMIT .. OFFSET.
@features_1486_li
#Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1481_h3
@features_1487_h3
#Derby Compatibility Mode
@features_1482_p
@features_1488_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> .
@features_1483_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1489_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> .
@features_1484_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1490_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.
@features_1491_li
#Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1485_h3
@features_1492_h3
#HSQLDB Compatibility Mode
@features_1486_p
@features_1493_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> .
@features_1487_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1494_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> .
@features_1488_li
@features_1495_li
#When converting the scale of decimal data, the number is only converted if the new scale is smaller than the current scale. Usually, the scale is converted and 0s are added if required.
@features_1489_li
#Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
@features_1490_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1496_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.
@features_1491_h3
@features_1497_h3
#MS SQL Server Compatibility Mode
@features_1492_p
@features_1498_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> .
@features_1493_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1499_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> .
@features_1494_li
#Identifiers may be quoted using square brackets as in [Test].
@features_1500_li
#Identifiers may be quoted using square brackets as in <code class="notranslate">[Test]</code> .
@features_1495_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1501_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.
@features_1502_li
#Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1496_h3
@features_1503_h3
#MySQL Compatibility Mode
@features_1497_p
@features_1504_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> .
@features_1498_li
#When inserting data, if a column is defined to be NOT NULL and NULL is inserted, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
@features_1505_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, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
@features_1499_li
#Creating indexes in the CREATE TABLE statement is allowed.
@features_1506_li
#Creating indexes in the <code class="notranslate">CREATE TABLE</code> statement is allowed.
@features_1500_li
@features_1507_li
#Meta data calls return identifiers in lower case.
@features_1501_li
@features_1508_li
#When converting a floating point number to an integer, the fractional digits are not truncated, but the value is rounded.
@features_1502_h3
@features_1509_li
#Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1510_h3
#Oracle Compatibility Mode
@features_1503_p
@features_1511_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> .
@features_1504_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1512_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> .
@features_1505_li
#When using unique indexes, multiple rows with NULL in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
@features_1513_li
#When using unique indexes, multiple rows with <code class="notranslate">NULL</code> in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
@features_1514_li
#Concatenating <code class="notranslate">NULL</code> with another value results in the other value.
@features_1506_h3
@features_1515_h3
#PostgreSQL Compatibility Mode
@features_1507_p
@features_1516_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> .
@features_1508_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1509_li
#Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
@features_1517_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> .
@features_1510_li
@features_1518_li
#When converting a floating point number to an integer, the fractional digits are not be truncated, but the value is rounded.
@features_1511_li
#The system columns 'CTID' and 'OID' are supported.
@features_1519_li
#The system columns <code class="notranslate">CTID</code> and <code class="notranslate">OID</code> are supported.
@features_1512_h2
@features_1520_h2
#Auto-Reconnect
@features_1513_p
@features_1521_p
#The auto-reconnect feature causes the JDBC driver to reconnect to the database if the connection is lost. The automatic re-connect only occurs when auto-commit is enabled; if auto-commit is disabled, an exception is thrown.
@features_1514_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 INFORMATION_SCHEMA.SESSION_STATE contains all client side state that is re-created.
@features_1522_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> contains all client side state that is re-created.
@features_1515_h2
@features_1523_h2
#Automatic Mixed Mode
@features_1516_p
@features_1524_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. You can use the same database URL no matter if the database is already open or not.
@features_1517_p
@features_1525_p
#When using this mode, the first connection to the database is made in embedded mode, and additionally a server is started internally. If the database is already open in another process, the server mode is used automatically.
@features_1518_p
#The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads .lock.db file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
@features_1526_p
#The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads <code class="notranslate">.lock.db</code> file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
@features_1519_p
@features_1527_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. This mode is not supported for in-memory databases.
@features_1520_p
@features_1528_p
#Here is an example how to use this mode. Application 1 and 2 are not necessarily started on the same computer, but they need to have access to the database files. Application 1 and 2 are typically two different processes (however they could run within the same process).
@features_1521_h2
@features_1529_h2
トレースオプションを使用する
@features_1522_p
@features_1530_p
アプリケーション内の問題を見つけるために、時々、何のデータベースオペレーションがどこで実行されているかを知るのは良い方法です。このデータベースは次のトレースの特徴を提供します:
@features_1523_li
System.out と (または) ファイルをトレースする
@features_1531_li
#Trace to <code class="notranslate">System.out</code> and/or to a file
@features_1524_li
トレースレベル OFF、ERROR、INFO と DEBUG をサポート
@features_1532_li
#Support for trace levels <code class="notranslate">OFF, ERROR, INFO, DEBUG</code>
@features_1525_li
@features_1533_li
トレースファイルの最大サイズの設定が可能
@features_1526_li
@features_1534_li
#It is possible to generate Java source code from the trace file
@features_1527_li
@features_1535_li
手動でファイルを作成することによって、ランタイムでトレースが可能
@features_1528_h3
@features_1536_h3
トレースオプション
@features_1529_p
トレースオプションを可能にする簡単な方法は、データベースURLにトレースオプションを設定することです。二つの設定があり、ひとつは、System.out (TRACE_LEVEL_SYSTEM_OUT) トレーシングで、もうひとつはファイルトレーシング(TRACE_LEVEL_FILE)です。トレースレベルは、0 が OFF、1 が ERROR (デフォルト)、2 が INFO で 3 が DEBUGです。両方のレベルがDEBUGに設定されたデータベースURLです:
@features_1537_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> ). 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:
@features_1530_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 System.out tracing) or <code class="notranslate">SET TRACE_LEVEL_FILE level</code> (for file tracing). Example:
@features_1538_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). Example:
@features_1531_h3
@features_1539_h3
トレースファイルの最大サイズを設定
@features_1532_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 .old and a new file is created. If another .old file exists, it is deleted. The size limit can be changed using the SQL statement <code class="notranslate">SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . Example:
@features_1540_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. 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> . Example:
@features_1533_h3
@features_1541_h3
Javaコード生成
@features_1534_p
#When setting the trace level to INFO or DEBUG, Java source code is generated as well. This allows to reproduce problems more easily. The trace file looks like this:
@features_1542_p
#When setting the trace level to <code class="notranslate">INFO</code> or <code class="notranslate">DEBUG</code> , Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this:
@features_1535_p
#To filter the Java source code, use the ConvertTraceFile tool as follows:
@features_1543_p
#To filter the Java source code, use the <code class="notranslate">ConvertTraceFile</code> tool as follows:
@features_1536_p
@features_1544_p
#The generated file <code class="notranslate">Test.java</code> will contain the Java source code. The generated source code may be too large to compile (the size of a Java method is limited). If this is the case, the source code needs to be split in multiple methods. The password is not listed in the trace file and therefore not included in the source code.
@features_1537_h2
@features_1545_h2
#Using Other Logging APIs
@features_1538_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 System.out. In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
@features_1546_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> . In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
@features_1539_a
@features_1547_a
#SLF4J
@features_1540_p
@features_1548_p
#is a simple facade for various logging APIs and allows to plug in the desired implementation at deployment time. SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), Java logging, x4juli, and Simple Log.
@features_1541_p
@features_1549_p
#To enable SLF4J, set the file trace level to 4 in the database URL:
@features_1542_p
#Changing the log mechanism is not possible after the database is open, that means executing the SQL statement SET TRACE_LEVEL_FILE 4 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 &lt;database&gt;.trace.db for error messages.
@features_1550_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> 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.
@features_1543_h2
@features_1551_h2
読み取り専用データベース
@features_1544_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 SELECT and CALL 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 Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
@features_1552_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. 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> .
@features_1545_h2
@features_1553_h2
#Read Only Databases in Zip or Jar File
@features_1546_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 Backup tool or the BACKUP SQL statement:
@features_1554_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:
@features_1547_p
@features_1555_p
#The database must not have pending changes, that means you need to close all connections to the database, open one single connection, and then execute the statement. Afterwards, you can log out, and directly open the database in the zip file using the following database URL:
@features_1548_p
@features_1556_p
#Databases in zip files are read-only. The performance for some queries will be slower than when using a regular database, because random access in zip files is not supported (only streaming). How much this affects the performance depends on the queries and the data. The database is not read in memory; therefore large databases are supported as well. The same indexes are used as when using a regular database.
@features_1549_h2
@features_1557_h2
ディスクスペースが少ない状況での正しい取り扱い
@features_1550_p
#If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement SET DATABASE_EVENT_LISTENER or use a database URL of the form jdbc:h2:~/test;DATABASE_EVENT_LISTENER='com.acme.DbListener' (the quotes around the class name are required). See also the DatabaseEventListener API.
@features_1558_p
#If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement <code 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> (the quotes around the class name are required). See also the <code class="notranslate">DatabaseEventListener</code> API.
@features_1551_h3
@features_1559_h3
破損したデータベースを開く
@features_1552_p
@features_1560_p
boot info (始動時に実行されるSQLスクリプト) が破損しているため、データベースを開くことができない場合、データベースイベントリスナーを指定することでデータベースを開くことができます。例外は記録されますが、データベースの開始は続行します。
@features_1553_h2
@features_1561_h2
computed column / ベースインデックスの機能
@features_1554_p
@features_1562_p
#Function indexes are not directly supported by this database, but they can be emulated by using computed columns. For example, if an index on the upper-case version of a column is required, create a computed column with the upper-case version of the original column, and create an index for this column:
@features_1555_p
@features_1563_p
#When inserting data, it is not required (and not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table:
@features_1556_h2
@features_1564_h2
多次元インデックス
@features_1557_p
@features_1565_p
効率的な多次元の (空間的) 領域のクエリーを実行するためにツールを提供します。このデータベースは専門的な空間的インデックス (R-Tree またはより小さいもの) をサポートしていません。代わりに、B-Treeインデックスが使われています。それぞれのレコードに対して、多次元のキーは、単数範囲 (スカラー) の値に変換 (位置づけ) されます。この値は、space-filling curve (空間充填曲線) で位置を指定します。
@features_1558_p
@features_1566_p
現在、Z-order (N-order または Morton-order とも呼ばれています) が使用されています; Hilbert curveも使用できますが、実装はより複雑です。多次元の値を変換するアルゴリズムは、bit-interleavingと呼ばれています。B-Treeインデックス (通常は computed columnを使用します)を使用することで、スカラーの値はインデックスをつけられます。
@features_1559_p
@features_1567_p
最初のカラムにインデックスを使用する上で、メソッドは徹底的なパフォーマンスの改良をもたらすことができます。データと次元の数によりますが、改良は通常、factor 5よりも高いものです。指定された多次元の範囲から、ツールはSQLクエリーを生成します。使用されたメソッドは、データベースに依存しておらず、ツールは簡単に他のデータベースに移植することができます。ツールの使用方法の例は、TestMultiDimension.java で提供されているサンプルコードをご覧下さい。
@features_1560_h2
@features_1568_h2
パスワードを使用する
@features_1561_h3
@features_1569_h3
安全なパスワードを使用する
@features_1562_p
@features_1570_p
弱いパスワードは、暗号化やセキュリティプロトコルに取るに足らず、解読されてしまうことを覚えておいて下さい。辞書で見つけられるようなパスワードは使用しないでください。また、数字を付け足してもそのようなパスワードは安全にはなりません。良いパスワードを作る方法は、覚えやすい、文章の最初の文字を使う、大文字と小文字を使う、特別な文字が含まれているものを作る、です。例:
@features_1563_p
@features_1571_p
i'sE2rtPiUKtT (もしトリックを知っていれば、このパスワードは覚えやすいものです)
@features_1564_h3
@features_1572_h3
パスワード: Stringの代わりにChar Arraysを使用する
@features_1565_p
@features_1573_p
Java Stringは不変のオブジェクトであり、アプリケーションによって安全に壊されることはできません。Stringの作成後、Stringは少なくともガベージコレクションになるまで、コンピューターのメインメモリ内にとどまるでしょう。ガベージコレクションはアプリケーションによって制御されず、ガベージコレクションであっても、データはまだメモリにとどまっているでしょう。パスワードが含まれるメモリの一部をディスクと取り換えることも可能でしょう (十分でないメインメモリも使用可能のため)。
@features_1566_p
@features_1574_p
アタッカーはオペレーティングシステムのスワップファイルにアクセスするでしょう。したがって、パスワードを保存するために、Stringの代わりにchar arrayを使用するのは良い方法です。char arrayは使用後クリアにされるので (0で埋められます)、パスワードはスワップファイルに保存されません。
@features_1567_p
@features_1575_p
このデータベースは、ユーザーパスワードとファイルパスワードを認証するために、Stringの代わりにchar arrayを使用することをサポートしています。次のコードはこのように使用されます:
@features_1568_p
#This example requires Java 1.6. When using Swing, use javax.swing.JPasswordField.
@features_1576_p
#This example requires Java 1.6. When using Swing, use <code class="notranslate">javax.swing.JPasswordField</code> .
@features_1569_h3
@features_1577_h3
ユーザー名 と (または) パスワードをURLで認証する
@features_1570_p
@features_1578_p
#Instead of passing the user name as a separate parameter as in <code class="notranslate">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">Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter.
@features_1571_h2
@features_1579_h2
ユーザー定義の関数とストアドプロシージャ
@features_1572_p
@features_1580_p
組み込み関数に加えて、このデータベースはユーザー定義のJava関数をサポートしています。同様に、このデータベースではJava関数はストアドプロシージャとして使用されています。関数は、使用される前に宣言 (登録) されていなければなりません。static Javaメソッドのみサポートされています; クラスとメソッドの両方が public である必要があります。Javaメソッドの例:
@features_1573_p
Java関数は、CREATE ALIAS と呼ばれるデータベースに登録されていなければなりません:
@features_1581_p
#The Java function must be registered in the database by calling <code class="notranslate">CREATE ALIAS</code> :
@features_1574_p
完全なサンプルアプリケーションは src/test/org/h2/samples/Function.java をご覧下さい。
@features_1582_p
#For a complete sample application, see <code class="notranslate">src/test/org/h2/samples/Function.java</code> .
@features_1575_h3
@features_1583_h3
データタイプマッピング関数
@features_1576_p
#Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. Instead, the result of the function is NULL. If the function should be called if a parameter is NULL, you need to use 'java.lang.Integer' instead of 'int'.
@features_1584_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.
@features_1577_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: java.lang.Object is mapped to OTHER (a serialized object). Therefore, java.lang.Object can not be used to match all SQL types (matching all SQL types is not supported). The second special case is Object[]: arrays of any class are mapped to ARRAY.
@features_1585_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> .
@features_1578_h3
@features_1586_h3
接続を必要とする関数
@features_1579_p
#If the first parameter of a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
@features_1587_p
#If the first parameter of a Java function is a <code class="notranslate">java.sql.Connection</code> , then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
@features_1580_h3
@features_1588_h3
例外を投げる関数
@features_1581_p
関数が例外を投げたら、現在のステートメントはロールバックされ、例外はアプリケーションに投げられます。
@features_1589_p
#If a function throws an exception, then the current statement is rolled back and the exception is thrown to the application.
@features_1582_h3
@features_1590_h3
Result Setを返す関数
@features_1583_p
関数はresult setを返します。このような関数はCALLステートメントと一緒に呼ばれます:
@features_1591_p
#Functions may returns a result set. Such a function can be called with the <code class="notranslate">CALL</code> statement:
@features_1584_h3
@features_1592_h3
SimpleResultSetを使用する
@features_1585_p
@features_1593_p
#A function can create a result set using the SimpleResultSet tool:
@features_1586_h3
@features_1594_h3
関数をテーブルとして使用する
@features_1587_p
@features_1595_p
#A function that returns a result set can be used like a table. However, in this case the function is called at least twice: first while parsing the statement to collect the column names (with parameters set to null 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> .
@features_1588_h2
@features_1596_h2
トリガー
@features_1589_p
#This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see src/test/org/h2/samples/TriggerSample.java. A Java trigger must implement the interface org.h2.api.Trigger. The trigger class must be available in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
@features_1597_p
#This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see <code 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 in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
@features_1590_p
@features_1598_p
他のテーブルのクエリーかデータのアップデートに接続を使用することができます。トリガーはその時データベースで定義されている必要があります:
@features_1591_p
#The trigger can be used to veto a change, by throwing a SQLException.
@features_1599_p
#The trigger can be used to veto a change by throwing a <code class="notranslate">SQLException</code> .
@features_1592_h2
@features_1600_h2
データベースをコンパクトにする
@features_1593_p
データベースファイルの空のスペースは自動的に再利用されます。インデックスを再構築するもっとも簡単な方法は、データベースが閉じられている間に .index.db ファイルを削除します。しかし、一部状況では (例えば、データベースの多数のデータを削除した後)、データベースのサイズを縮小したい場合があります (データベースをコンパクトにする)。そのためのサンプルです:
@features_1601_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 while the database is closed. However in some situations (for example after deleting a lot of data in a database), one sometimes wants to shrink the size of the database (compact a database). Here is a sample function to do this:
@features_1594_p
サンプルアプリケーション org.h2.samples.Compact もご覧下さい。データベースのバックアップを作るのと、スクリプトからデータベースを再構築するのにSCRIPT / RUNSCRIPT コマンドを使用することができます。
@features_1602_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 of a database and re-build the database from the script.
@features_1595_h2
@features_1603_h2
キャッシュの設定
@features_1596_p
@features_1604_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> .
@features_1597_p
@features_1605_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> .
@features_1598_p
@features_1606_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 is listed for the data and index file.
@fragments_1000_b
......@@ -4901,7 +4925,7 @@ Sourceファイル
#Restrictions
@jaqu_1009_p
#Primitive types (eg. boolean, int, long, double) are not supported. Use Boolean, Integer, Long, and Double instead.
#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.
@jaqu_1010_h3
#Why in Java?
......@@ -4915,91 +4939,97 @@ Sourceファイル
@jaqu_1013_p
#Currently, JaQu is only tested with the H2 database. The API may change in future versions. JaQu is not part of the h2 jar file, however the source code is included in H2, under:
@jaqu_1014_li
#src/test/org/h2/test/jaqu/* (samples and tests)
@jaqu_1014_code
#src/test/org/h2/test/jaqu/*
@jaqu_1015_li
#src/tools/org/h2/jaqu/* (framework)
#(samples and tests)
@jaqu_1016_h2
@jaqu_1016_code
#src/tools/org/h2/jaqu/*
@jaqu_1017_li
#(framework)
@jaqu_1018_h2
#Building the JaQu library
@jaqu_1017_p
@jaqu_1019_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> .
@jaqu_1018_h2
@jaqu_1020_h2
必要条件
@jaqu_1019_p
@jaqu_1021_p
#JaQu requires Java 1.5. Annotations are not need. Currently, JaQu is only tested with the H2 database engine, however in theory it should work with any database that supports the JDBC API.
@jaqu_1020_h2
@jaqu_1022_h2
#Example Code
@jaqu_1021_h2
@jaqu_1023_h2
#Configuration
@jaqu_1022_p
@jaqu_1024_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. Example:
@jaqu_1023_p
#The method 'define()' 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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
@jaqu_1025_p
#The method <code class="notranslate">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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
@jaqu_1024_h2
@jaqu_1026_h2
#Natural Syntax
@jaqu_1025_p
@jaqu_1027_p
#The plan is to support more natural (pure Java) syntax in conditions. 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:
@jaqu_1026_h2
@jaqu_1028_h2
#Other Ideas
@jaqu_1027_p
@jaqu_1029_p
#This project has just been started, and nothing is fixed yet. Some ideas for what to implement are:
@jaqu_1028_li
@jaqu_1030_li
#Support queries on collections (instead of using a database).
@jaqu_1029_li
@jaqu_1031_li
#Provide API level compatibility with JPA (so that JaQu can be used as an extension of JPA).
@jaqu_1030_li
@jaqu_1032_li
#Internally use a JPA implementation (for example Hibernate) instead of SQL directly.
@jaqu_1031_li
@jaqu_1033_li
#Use PreparedStatements and cache them.
@jaqu_1032_h2
@jaqu_1034_h2
#Related Projects
@jaqu_1033_a
@jaqu_1035_a
#Dreamsource ORM
@jaqu_1034_a
@jaqu_1036_a
#Empire-db
@jaqu_1035_a
@jaqu_1037_a
#JEQUEL: Java Embedded QUEry Language
@jaqu_1036_a
@jaqu_1038_a
#Joist
@jaqu_1037_a
@jaqu_1039_a
#JoSQL
@jaqu_1038_a
@jaqu_1040_a
#LIQUidFORM
@jaqu_1039_a
@jaqu_1041_a
#Quaere (Alias implementation)
@jaqu_1040_a
@jaqu_1042_a
#Quaere
@jaqu_1041_a
@jaqu_1043_a
#Querydsl
@jaqu_1042_a
@jaqu_1044_a
#Squill
@license_1000_h1
......
......@@ -1244,13 +1244,13 @@ features_1345_a=Changing other settings
features_1346_td=jdbc\:h2\:&lt;url&gt;;&lt;setting&gt;\=&lt;value&gt;[;&lt;setting&gt;\=&lt;value&gt;...]
features_1347_td=jdbc\:h2\:file\:~/sample;TRACE_LEVEL_SYSTEM_OUT\=3
features_1348_h2=Connecting to an Embedded (Local) Database
features_1349_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 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 File.createTempFile). To point to the user home directory, use <code class\="notranslate">~/</code> , as in\: <code class\="notranslate">jdbc\:h2\:~/test</code> .
features_1349_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 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> .
features_1350_h2=Memory-Only Databases
features_1351_p=For certain use cases (for example\: rapid prototyping, testing, high performance operations, read-only databases), it may not be required to persist data, or persist changes to the data. This database supports the memory-only mode, where the data is not persisted.
features_1352_p=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 means opening two different (private) databases.
features_1353_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> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
features_1354_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> .
features_1355_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 ;DB_CLOSE_DELAY\=-1 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> .
features_1355_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 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> .
features_1356_h2=Database Files Encryption
features_1357_p=The database files can be encrypted. Two encryption algorithms are supported\: AES and XTEA. To use file encryption, you need to specify the encryption algorithm (the 'cipher') and the file password (in addition to the user password) when connecting to the database.
features_1358_h3=Creating a New Database with File Encryption
......@@ -1265,25 +1265,25 @@ features_1366_p=The following file locking methods are implemented\:
features_1367_li=The default method is 'file' and uses a watchdog thread to protect the database file. The watchdog reads the lock file each second.
features_1368_li=The second method is 'socket' and opens a server socket. The socket method does not require reading the lock file every second. The socket method should only be used if the database files are only accessed by one (and always the same) computer.
features_1369_li=It is also possible to open the database without file locking; in this case it is up to the application to protect the database files.
features_1370_p=To open the database with a different file locking method, use the parameter 'FILE_LOCK'. The following code opens the database with the 'socket' locking method\:
features_1370_p=To open the database with a different file locking method, use the parameter <code class\="notranslate">FILE_LOCK</code> . The following code opens the database with the 'socket' locking method\:
features_1371_p=The following code forces the database to not create a lock file at all. Please note that this is unsafe as another process is able to open the same database, possibly leading to data corruption\:
features_1372_p=For more information about the algorithms, see <a href\="advanced.html\#file_locking_protocols">Advanced / File Locking Protocols</a> .
features_1373_h2=Opening a Database Only if it Already Exists
features_1374_p=By default, when an application calls <code class\="notranslate">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> to the database URL. In this case, if the database does not already exist, an exception is thrown when trying to connect. The connection only succeeds when the database already exists. The complete URL may look like this\:
features_1375_h2=Closing a Database
features_1376_h3=Delayed Database Closing
features_1377_p=Usually, a database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible to keep at least one connection open. The automatic closing of a database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY &lt;seconds&gt;. The parameter &lt;seconds&gt; specifies the number of seconds to keep a database open after the last connection to it was closed. The following statement will keep a database open for 10 seconds after the last connection was closed\:
features_1377_p=Usually, a database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible to keep at least one connection open. The automatic closing of a database can be delayed or disabled with the SQL statement <code class\="notranslate">SET DB_CLOSE_DELAY &lt;seconds&gt;</code> . The parameter &lt;seconds&gt; specifies the number of seconds to keep a database open after the last connection to it was closed. The following statement will keep a database open for 10 seconds after the last connection was closed\:
features_1378_p=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> .
features_1379_h3=Don't Close a Database when the VM Exits
features_1380_p=By default, a database is closed when the last connection is closed. However, if it is never closed, the database is closed when the virtual machine exits normally, using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). For those cases, the automatic closing of the database can be disabled in the database URL. The first connection (the one that is opening the database) needs to set the option in the database URL (it is not possible to change the setting afterwards). The database URL to disable database closing on exit is\:
features_1381_h2=Log Index Changes
features_1382_p=Usually, changes to the index file are not logged for performance. If the index file is corrupt or missing when opening a database, it is re-created from the data. The index file can get corrupt when the database is not shut down correctly, because of power failure or abnormal program termination. In some situations, for example when using very large databases (over a few hundred MB), re-creating the index file takes very long. In these situations it may be better to log changes to the index file, so that recovery from a corrupted index file is fast. To enable log index changes, add LOG\=2 to the URL, as in <code class\="notranslate">jdbc\:h2\:~/test;LOG\=2</code> . This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
features_1383_h2=Ignore Unknown Settings
features_1384_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 PREFERDOSLIKELINEENDS and IGNOREDRIVERPRIVILEGES are such examples; they are simply ignored to improve the compatibility with OpenOffice.org. If an application passes other parameters when connecting to the database, usually the database throws an exception saying the parameter is not supported. It is possible to ignored such parameters by adding ;IGNORE_UNKNOWN_SETTINGS\=TRUE to the database URL.
features_1384_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; 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.
features_1385_h2=Changing Other Settings when Opening a Connection
features_1386_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 connecting. For a list of supported settings, see <a href\="grammar.html">SQL Grammar</a> .
features_1387_h2=Custom File Access Mode
features_1388_p=Usually, the database opens log, data and index files with the access mode 'rw', meaning read-write (except for read only databases, where the mode 'r' is used). To open a database in read-only mode if the files are not read-only, use ACCESS_MODE_DATA\=r. Also supported are 'rws' and 'rwd'. The access mode used for log files is set via ACCESS_MODE_LOG; for data and index files use ACCESS_MODE_DATA. These settings must be specified in the database URL\:
features_1388_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). 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> . These settings must be specified in the database URL\:
features_1389_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.
features_1390_h2=Multiple Connections
features_1391_h3=Opening Multiple Databases at the Same Time
......@@ -1295,7 +1295,7 @@ features_1396_p=This database is multithreading-safe. That means, if an applicat
features_1397_h3=Locking, Lock-Timeout, Deadlocks
features_1398_p=The database uses table level locks to give each connection a consistent state of the data. There are two kinds of locks\: read locks (shared locks) and write locks (exclusive locks). All locks are released when the transaction commits or rolls back. When using the default transaction isolation level 'read committed', read locks are already released after each statement.
features_1399_p=If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If a connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
features_1400_p=Usually, SELECT 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 SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks\:
features_1400_p=Usually, <code class\="notranslate">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. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. The following statements generate locks\:
features_1401_th=Type of Lock
features_1402_th=SQL Statement
features_1403_td=Read
......@@ -1313,187 +1313,195 @@ features_1414_td=Write
features_1415_td=ALTER TABLE TEST ...;
features_1416_td=CREATE INDEX ... ON TEST ...;
features_1417_td=DROP INDEX ...;
features_1418_p=The number of seconds until a lock timeout exception is thrown can be set separately for each connection using the SQL command SET LOCK_TIMEOUT &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
features_1418_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> . 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.
features_1419_h2=Database File Layout
features_1420_p=There are a number of files created for persistent databases. Unlike some other databases, not every table and/or index is stored in its own file. Instead, usually only the following files are created\: a data file, an index file, a log file, and a database lock file (exists only while the database is in use). In addition to that, a file is created for each large object (CLOB/BLOB) larger than a certain size, and temporary files for large result sets. If the database trace option is enabled, trace files are created. The following files can be created by the database\:
features_1421_th=File Name
features_1422_th=Description
features_1423_th=Number of Files
features_1424_td=test.data.db
features_1425_td=Data file.
features_1426_td=Contains the data for all tables.
features_1427_td=Format\: &lt;database&gt;.data.db
features_1424_td=test.h2.db
features_1425_td=Database file.
features_1426_td=Contains the data and index data for all tables.
features_1427_td=Format\: <code class\="notranslate">&lt;database&gt;.h2.db</code>
features_1428_td=1 per database
features_1429_td=test.index.db
features_1430_td=Index file.
features_1431_td=Contains the data for all (b tree) indexes.
features_1432_td=Format\: &lt;database&gt;.index.db
features_1429_td=test.data.db
features_1430_td=Data file.
features_1431_td=Contains the data for all tables.
features_1432_td=Format\: <code class\="notranslate">&lt;database&gt;.data.db</code>
features_1433_td=1 per database
features_1434_td=test.0.log.db
features_1435_td=Transaction log file.
features_1436_td=The transaction log is used for recovery.
features_1437_td=Format\: &lt;database&gt;.&lt;id&gt;.log.db
features_1438_td=0 or more per database
features_1439_td=test.lock.db
features_1440_td=Database lock file.
features_1441_td=Exists only while the database is open.
features_1442_td=Format\: &lt;database&gt;.lock.db
features_1443_td=1 per database
features_1444_td=test.trace.db
features_1445_td=Trace file.
features_1446_td=Contains trace information.
features_1447_td=Format\: &lt;database&gt;.trace.db
features_1448_td=If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
features_1449_td=1 per database
features_1450_td=test.lobs.db/1.t15.lob.db
features_1451_td=Large object.
features_1452_td=Contains the data for BLOB or CLOB values.
features_1453_td=Format\: &lt;id&gt;.t&lt;tableId&gt;.lob.db
features_1454_td=1 per value
features_1455_td=test.123.temp.db
features_1456_td=Temporary file.
features_1457_td=Contains a temporary blob or a large result set.
features_1458_td=Format\: &lt;database&gt;.&lt;id&gt;.temp.db
features_1459_td=1 per object
features_1460_h3=Moving and Renaming Database Files
features_1461_p=Database name and location are not stored inside the database files.
features_1462_p=While a database is closed, the files can be moved to another directory, and they can be renamed as well (as long as all files start with the same name).
features_1463_p=As there is no platform specific data in the files, they can be moved to other operating systems without problems.
features_1464_h3=Backup
features_1465_p=When the database is closed, it is possible to backup the database files. Please note that index files do not need to be backed up, because they contain redundant data, and will be recreated automatically if they don't exist.
features_1466_p=To backup data while the database is running, the SQL command SCRIPT can be used.
features_1467_h2=Logging and Recovery
features_1468_p=Whenever data is modified in the database and those changes are committed, the changes are logged to disk (except for in-memory objects). The changes to the data file itself are usually written later on, to optimize disk access. If there is a power failure, the data and index files are not up-to-date. But because the changes are in the log file, the next time the database is opened, the changes that are in the log file are re-applied automatically.
features_1469_p=Please note that index file updates are not logged by default. If the database is opened and recovery is required, the index file is rebuilt from scratch.
features_1470_p=There is usually only one log file per database. This file grows until the database is closed successfully, and is then deleted. Or, if the file gets too big, the database switches to another log file (with a higher id). It is possible to force the log switching by using the CHECKPOINT command.
features_1471_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 the summary (object allocation table) is not read in this case, so opening the database takes longer.
features_1472_h2=Compatibility
features_1473_p=All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however\:
features_1474_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 IGNORECASE\=TRUE to the database URL (example\: <code class\="notranslate">jdbc\:h2\:~/test;IGNORECASE\=TRUE</code> ).
features_1475_h3=Compatibility Modes
features_1476_p=For certain features, this database can emulate the behavior of specific databases. Not all features or differences of those databases are implemented. Here is the list of currently supported modes and the differences to the regular mode\:
features_1477_h3=DB2 Compatibility Mode
features_1478_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> .
features_1479_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1480_li=Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative for LIMIT .. OFFSET.
features_1481_h3=Derby Compatibility Mode
features_1482_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> .
features_1483_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1484_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1485_h3=HSQLDB Compatibility Mode
features_1486_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> .
features_1487_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1488_li=When converting the scale of decimal data, the number is only converted if the new scale is smaller than the current scale. Usually, the scale is converted and 0s are added if required.
features_1489_li=Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
features_1490_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1491_h3=MS SQL Server Compatibility Mode
features_1492_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> .
features_1493_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1494_li=Identifiers may be quoted using square brackets as in [Test].
features_1495_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1496_h3=MySQL Compatibility Mode
features_1497_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> .
features_1498_li=When inserting data, if a column is defined to be NOT NULL and NULL is inserted, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
features_1499_li=Creating indexes in the CREATE TABLE statement is allowed.
features_1500_li=Meta data calls return identifiers in lower case.
features_1501_li=When converting a floating point number to an integer, the fractional digits are not truncated, but the value is rounded.
features_1502_h3=Oracle Compatibility Mode
features_1503_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> .
features_1504_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1505_li=When using unique indexes, multiple rows with NULL in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
features_1506_h3=PostgreSQL Compatibility Mode
features_1507_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> .
features_1508_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1509_li=Concatenation with NULL results in NULL. Usually, NULL is treated as an empty string if only one of the operands is NULL, and NULL is only returned if both operands are NULL.
features_1510_li=When converting a floating point number to an integer, the fractional digits are not be truncated, but the value is rounded.
features_1511_li=The system columns 'CTID' and 'OID' are supported.
features_1512_h2=Auto-Reconnect
features_1513_p=The auto-reconnect feature causes the JDBC driver to reconnect to the database if the connection is lost. The automatic re-connect only occurs when auto-commit is enabled; if auto-commit is disabled, an exception is thrown.
features_1514_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 INFORMATION_SCHEMA.SESSION_STATE contains all client side state that is re-created.
features_1515_h2=Automatic Mixed Mode
features_1516_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. You can use the same database URL no matter if the database is already open or not.
features_1517_p=When using this mode, the first connection to the database is made in embedded mode, and additionally a server is started internally. If the database is already open in another process, the server mode is used automatically.
features_1518_p=The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads .lock.db file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
features_1519_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. This mode is not supported for in-memory databases.
features_1520_p=Here is an example how to use this mode. Application 1 and 2 are not necessarily started on the same computer, but they need to have access to the database files. Application 1 and 2 are typically two different processes (however they could run within the same process).
features_1521_h2=Using the Trace Options
features_1522_p=To find problems in an application, it is sometimes good to see what database operations where executed. This database offers the following trace features\:
features_1523_li=Trace to System.out and/or a file
features_1524_li=Support for trace levels OFF, ERROR, INFO, and DEBUG
features_1525_li=The maximum size of the trace file can be set
features_1526_li=It is possible to generate Java source code from the trace file
features_1527_li=Trace can be enabled at runtime by manually creating a file
features_1528_h3=Trace Options
features_1529_p=The simplest way to enable the trace option is setting it in the database URL. There are two settings, one for System.out (TRACE_LEVEL_SYSTEM_OUT) tracing, and one for file tracing (TRACE_LEVEL_FILE). The trace levels are 0 for OFF, 1 for ERROR (the default), 2 for INFO and 3 for DEBUG. A database URL with both levels set to DEBUG is\:
features_1530_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 System.out tracing) or <code class\="notranslate">SET TRACE_LEVEL_FILE level</code> (for file tracing). Example\:
features_1531_h3=Setting the Maximum Size of the Trace File
features_1532_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 .old and a new file is created. If another .old file exists, it is deleted. The size limit can be changed using the SQL statement <code class\="notranslate">SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . Example\:
features_1533_h3=Java Code Generation
features_1534_p=When setting the trace level to INFO or DEBUG, Java source code is generated as well. This allows to reproduce problems more easily. The trace file looks like this\:
features_1535_p=To filter the Java source code, use the ConvertTraceFile tool as follows\:
features_1536_p=The generated file <code class\="notranslate">Test.java</code> will contain the Java source code. The generated source code may be too large to compile (the size of a Java method is limited). If this is the case, the source code needs to be split in multiple methods. The password is not listed in the trace file and therefore not included in the source code.
features_1537_h2=Using Other Logging APIs
features_1538_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 System.out. In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
features_1539_a=SLF4J
features_1540_p=is a simple facade for various logging APIs and allows to plug in the desired implementation at deployment time. SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), Java logging, x4juli, and Simple Log.
features_1541_p=To enable SLF4J, set the file trace level to 4 in the database URL\:
features_1542_p=Changing the log mechanism is not possible after the database is open, that means executing the SQL statement SET TRACE_LEVEL_FILE 4 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 &lt;database&gt;.trace.db for error messages.
features_1543_h2=Read Only Databases
features_1544_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 SELECT and CALL 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 Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
features_1545_h2=Read Only Databases in Zip or Jar File
features_1546_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 Backup tool or the BACKUP SQL statement\:
features_1547_p=The database must not have pending changes, that means you need to close all connections to the database, open one single connection, and then execute the statement. Afterwards, you can log out, and directly open the database in the zip file using the following database URL\:
features_1548_p=Databases in zip files are read-only. The performance for some queries will be slower than when using a regular database, because random access in zip files is not supported (only streaming). How much this affects the performance depends on the queries and the data. The database is not read in memory; therefore large databases are supported as well. The same indexes are used as when using a regular database.
features_1549_h2=Graceful Handling of Low Disk Space Situations
features_1550_p=If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement SET DATABASE_EVENT_LISTENER or use a database URL of the form jdbc\:h2\:~/test;DATABASE_EVENT_LISTENER\='com.acme.DbListener' (the quotes around the class name are required). See also the DatabaseEventListener API.
features_1551_h3=Opening a Corrupted Database
features_1552_p=If a database cannot be opened because the boot info (the SQL script that is run at startup) is corrupted, then the database can be opened by specifying a database event listener. The exceptions are logged, but opening the database will continue.
features_1553_h2=Computed Columns / Function Based Index
features_1554_p=Function indexes are not directly supported by this database, but they can be emulated by using computed columns. For example, if an index on the upper-case version of a column is required, create a computed column with the upper-case version of the original column, and create an index for this column\:
features_1555_p=When inserting data, it is not required (and not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table\:
features_1556_h2=Multi-Dimensional Indexes
features_1557_p=A tool is provided to execute efficient multi-dimension (spatial) range queries. This database does not support a specialized spatial index (R-Tree or similar). Instead, the B-Tree index is used. For each record, the multi-dimensional key is converted (mapped) to a single dimensional (scalar) value. This value specifies the location on a space-filling curve.
features_1558_p=Currently, Z-order (also called N-order or Morton-order) is used; Hilbert curve could also be used, but the implementation is more complex. The algorithm to convert the multi-dimensional value is called bit-interleaving. The scalar value is indexed using a B-Tree index (usually using a computed column).
features_1559_p=The method can result in a drastic performance improvement over just using an index on the first column. Depending on the data and number of dimensions, the improvement is usually higher than factor 5. The tool generates a SQL query from a specified multi-dimensional range. The method used is not database dependent, and the tool can easily be ported to other databases. For an example how to use the tool, please have a look at the sample code provided in TestMultiDimension.java.
features_1560_h2=Using Passwords
features_1561_h3=Using Secure Passwords
features_1562_p=Remember that weak passwords can be broken no matter of the encryption and security protocol. Don't use passwords that can be found in a dictionary. Also appending numbers does not make them secure. A way to create good passwords that can be remembered is, take the first letters of a sentence, use upper and lower case characters, and creatively include special characters. Example\:
features_1563_p=i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
features_1564_h3=Passwords\: Using Char Arrays instead of Strings
features_1565_p=Java Strings are immutable objects and cannot be safely 'destroyed' by the application. After creating a String, it will remain in the main memory of the computer at least until it is garbage collected. The garbage collection cannot be controlled by the application, and even if it is garbage collected the data may still remain in memory. It might also be possible that the part of memory containing the password is swapped to disk (because not enough main memory is available).
features_1566_p=An attacker might have access to the swap file of the operating system. It is therefore a good idea to use char arrays instead of Strings to store passwords. Char arrays can be cleared (filled with zeros) after use, and therefore the password will not be stored in the swap file.
features_1567_p=This database supports using char arrays instead of String to pass user and file passwords. The following code can be used to do that\:
features_1568_p=This example requires Java 1.6. When using Swing, use javax.swing.JPasswordField.
features_1569_h3=Passing the User Name and/or Password in the URL
features_1570_p=Instead of passing the user name as a separate parameter as in <code class\="notranslate">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">Connection conn \= DriverManager. getConnection("jdbc\:h2\:~/test;USER\=sa;PASSWORD\=123");</code> The settings in the URL override the settings passed as a separate parameter.
features_1571_h2=User-Defined Functions and Stored Procedures
features_1572_p=In addition to the built-in functions, this database supports user-defined Java functions. In this database, Java functions can be used as stored procedures as well. A function must be declared (registered) before it can be used. Only static Java methods are supported; both the class and the method must be public. Example Java method\:
features_1573_p=The Java function must be registered in the database by calling CREATE ALIAS\:
features_1574_p=For a complete sample application, see src/test/org/h2/samples/Function.java.
features_1575_h3=Function Data Type Mapping
features_1576_p=Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. Instead, the result of the function is NULL. If the function should be called if a parameter is NULL, you need to use 'java.lang.Integer' instead of 'int'.
features_1577_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\: java.lang.Object is mapped to OTHER (a serialized object). Therefore, java.lang.Object can not be used to match all SQL types (matching all SQL types is not supported). The second special case is Object[]\: arrays of any class are mapped to ARRAY.
features_1578_h3=Functions that require a Connection
features_1579_p=If the first parameter of a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
features_1580_h3=Functions throwing an Exception
features_1581_p=If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
features_1582_h3=Functions returning a Result Set
features_1583_p=Functions may returns a result set. Such a function can be called with the CALL statement\:
features_1584_h3=Using SimpleResultSet
features_1585_p=A function can create a result set using the SimpleResultSet tool\:
features_1586_h3=Using a Function as a Table
features_1587_p=A function that returns a result set can be used like a table. However, in this case the function is called at least twice\: first while parsing the statement to collect the column names (with parameters set to null 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> .
features_1588_h2=Triggers
features_1589_p=This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see src/test/org/h2/samples/TriggerSample.java. A Java trigger must implement the interface org.h2.api.Trigger. The trigger class must be available in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
features_1590_p=The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database\:
features_1591_p=The trigger can be used to veto a change, by throwing a SQLException.
features_1592_h2=Compacting a Database
features_1593_p=Empty space in the database file is re-used automatically. To re-build the indexes, the simplest way is to delete the .index.db file while the database is closed. However in some situations (for example after deleting a lot of data in a database), one sometimes wants to shrink the size of the database (compact a database). Here is a sample function to do this\:
features_1594_p=See also the sample application org.h2.samples.Compact. The commands SCRIPT / RUNSCRIPT can be used as well to create a backup of a database and re-build the database from the script.
features_1595_h2=Cache Settings
features_1596_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> .
features_1597_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> .
features_1598_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 is listed for the data and index file.
features_1434_td=test.index.db
features_1435_td=Index file.
features_1436_td=Contains the data for all (b tree) indexes.
features_1437_td=Format\: <code class\="notranslate">&lt;database&gt;.index.db</code>
features_1438_td=1 per database
features_1439_td=test.0.log.db
features_1440_td=Transaction log file.
features_1441_td=The transaction log is used for recovery.
features_1442_td=Format\: <code class\="notranslate">&lt;database&gt;.&lt;id&gt;.log.db</code>
features_1443_td=0 or more per database
features_1444_td=test.lock.db
features_1445_td=Database lock file.
features_1446_td=Exists only while the database is open.
features_1447_td=Format\: <code class\="notranslate">&lt;database&gt;.lock.db</code>
features_1448_td=1 per database
features_1449_td=test.trace.db
features_1450_td=Trace file.
features_1451_td=Contains trace information.
features_1452_td=Format\: <code class\="notranslate">&lt;database&gt;.trace.db</code>
features_1453_td=If the file is too big, it is renamed to <code class\="notranslate">&lt;database&gt;.trace.db.old</code>
features_1454_td=1 per database
features_1455_td=test.lobs.db/1.t15.lob.db
features_1456_td=Large object.
features_1457_td=Contains the data for BLOB or CLOB values.
features_1458_td=Format\: <code class\="notranslate">&lt;id&gt;.t&lt;tableId&gt;.lob.db</code>
features_1459_td=1 per value
features_1460_td=test.123.temp.db
features_1461_td=Temporary file.
features_1462_td=Contains a temporary blob or a large result set.
features_1463_td=Format\: <code class\="notranslate">&lt;database&gt;.&lt;id&gt;.temp.db</code>
features_1464_td=1 per object
features_1465_h3=Moving and Renaming Database Files
features_1466_p=Database name and location are not stored inside the database files.
features_1467_p=While a database is closed, the files can be moved to another directory, and they can be renamed as well (as long as all files start with the same name).
features_1468_p=As there is no platform specific data in the files, they can be moved to other operating systems without problems.
features_1469_h3=Backup
features_1470_p=When the database is closed, it is possible to backup the database files. Please note that index files do not need to be backed up, because they contain redundant data, and will be recreated automatically if they don't exist.
features_1471_p=To backup data while the database is running, the SQL command <code class\="notranslate">SCRIPT</code> can be used.
features_1472_h2=Logging and Recovery
features_1473_p=Whenever data is modified in the database and those changes are committed, the changes are logged to disk (except for in-memory objects). The changes to the data file itself are usually written later on, to optimize disk access. If there is a power failure, the data and index files are not up-to-date. But because the changes are in the log file, the next time the database is opened, the changes that are in the log file are re-applied automatically.
features_1474_p=Please note that index file updates are not logged by default. If the database is opened and recovery is required, the index file is rebuilt from scratch.
features_1475_p=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.
features_1476_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 the summary (object allocation table) is not read in this case, so opening the database takes longer.
features_1477_h2=Compatibility
features_1478_p=All database engines behave a little bit different. Where possible, H2 supports the ANSI SQL standard, and tries to be compatible to other databases. There are still a few differences however\:
features_1479_p=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> ).
features_1480_h3=Compatibility Modes
features_1481_p=For certain features, this database can emulate the behavior of specific databases. Not all features or differences of those databases are implemented. Here is the list of currently supported modes and the differences to the regular mode\:
features_1482_h3=DB2 Compatibility Mode
features_1483_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> .
features_1484_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> .
features_1485_li=Support for the syntax <code class\="notranslate">[OFFSET .. ROW] [FETCH ... ONLY]</code> as an alternative for <code class\="notranslate">LIMIT .. OFFSET</code> .
features_1486_li=Concatenating <code class\="notranslate">NULL</code> with another value results in the other value.
features_1487_h3=Derby Compatibility Mode
features_1488_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> .
features_1489_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> .
features_1490_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.
features_1491_li=Concatenating <code class\="notranslate">NULL</code> with another value results in the other value.
features_1492_h3=HSQLDB Compatibility Mode
features_1493_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> .
features_1494_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> .
features_1495_li=When converting the scale of decimal data, the number is only converted if the new scale is smaller than the current scale. Usually, the scale is converted and 0s are added if required.
features_1496_li=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.
features_1497_h3=MS SQL Server Compatibility Mode
features_1498_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> .
features_1499_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> .
features_1500_li=Identifiers may be quoted using square brackets as in <code class\="notranslate">[Test]</code> .
features_1501_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.
features_1502_li=Concatenating <code class\="notranslate">NULL</code> with another value results in the other value.
features_1503_h3=MySQL Compatibility Mode
features_1504_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> .
features_1505_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, then a 0 (or empty string, or the current timestamp for timestamp columns) value is used. Usually, this operation is not allowed and an exception is thrown.
features_1506_li=Creating indexes in the <code class\="notranslate">CREATE TABLE</code> statement is allowed.
features_1507_li=Meta data calls return identifiers in lower case.
features_1508_li=When converting a floating point number to an integer, the fractional digits are not truncated, but the value is rounded.
features_1509_li=Concatenating <code class\="notranslate">NULL</code> with another value results in the other value.
features_1510_h3=Oracle Compatibility Mode
features_1511_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> .
features_1512_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> .
features_1513_li=When using unique indexes, multiple rows with <code class\="notranslate">NULL</code> in all columns are allowed, however it is not allowed to have multiple rows with the same values otherwise.
features_1514_li=Concatenating <code class\="notranslate">NULL</code> with another value results in the other value.
features_1515_h3=PostgreSQL Compatibility Mode
features_1516_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> .
features_1517_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> .
features_1518_li=When converting a floating point number to an integer, the fractional digits are not be truncated, but the value is rounded.
features_1519_li=The system columns <code class\="notranslate">CTID</code> and <code class\="notranslate">OID</code> are supported.
features_1520_h2=Auto-Reconnect
features_1521_p=The auto-reconnect feature causes the JDBC driver to reconnect to the database if the connection is lost. The automatic re-connect only occurs when auto-commit is enabled; if auto-commit is disabled, an exception is thrown.
features_1522_p=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> contains all client side state that is re-created.
features_1523_h2=Automatic Mixed Mode
features_1524_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. You can use the same database URL no matter if the database is already open or not.
features_1525_p=When using this mode, the first connection to the database is made in embedded mode, and additionally a server is started internally. If the database is already open in another process, the server mode is used automatically.
features_1526_p=The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode. Therefore the main application should open the database first if possible. The first connection automatically starts a server on a random port. This server allows remote connections, however only to this database (to ensure that, the client reads <code class\="notranslate">.lock.db</code> file and sends the the random key that is stored there to the server). When the first connection is closed, the server stops. If other (remote) connections are still open, one of them will then start a server (auto-reconnect is enabled automatically).
features_1527_p=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. This mode is not supported for in-memory databases.
features_1528_p=Here is an example how to use this mode. Application 1 and 2 are not necessarily started on the same computer, but they need to have access to the database files. Application 1 and 2 are typically two different processes (however they could run within the same process).
features_1529_h2=Using the Trace Options
features_1530_p=To find problems in an application, it is sometimes good to see what database operations where executed. This database offers the following trace features\:
features_1531_li=Trace to <code class\="notranslate">System.out</code> and/or to a file
features_1532_li=Support for trace levels <code class\="notranslate">OFF, ERROR, INFO, DEBUG</code>
features_1533_li=The maximum size of the trace file can be set
features_1534_li=It is possible to generate Java source code from the trace file
features_1535_li=Trace can be enabled at runtime by manually creating a file
features_1536_h3=Trace Options
features_1537_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> ). 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\:
features_1538_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). Example\:
features_1539_h3=Setting the Maximum Size of the Trace File
features_1540_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. 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> . Example\:
features_1541_h3=Java Code Generation
features_1542_p=When setting the trace level to <code class\="notranslate">INFO</code> or <code class\="notranslate">DEBUG</code> , Java source code is generated as well. This simplifies reproducing problems. The trace file looks like this\:
features_1543_p=To filter the Java source code, use the <code class\="notranslate">ConvertTraceFile</code> tool as follows\:
features_1544_p=The generated file <code class\="notranslate">Test.java</code> will contain the Java source code. The generated source code may be too large to compile (the size of a Java method is limited). If this is the case, the source code needs to be split in multiple methods. The password is not listed in the trace file and therefore not included in the source code.
features_1545_h2=Using Other Logging APIs
features_1546_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> . In most cases, this is sufficient, however sometimes it is better to use the same facility as the application, for example Log4j. To do that, this database support SLF4J.
features_1547_a=SLF4J
features_1548_p=is a simple facade for various logging APIs and allows to plug in the desired implementation at deployment time. SLF4J supports implementations such as Logback, Log4j, Jakarta Commons Logging (JCL), Java logging, x4juli, and Simple Log.
features_1549_p=To enable SLF4J, set the file trace level to 4 in the database URL\:
features_1550_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> 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.
features_1551_h2=Read Only Databases
features_1552_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. 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> .
features_1553_h2=Read Only Databases in Zip or Jar File
features_1554_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\:
features_1555_p=The database must not have pending changes, that means you need to close all connections to the database, open one single connection, and then execute the statement. Afterwards, you can log out, and directly open the database in the zip file using the following database URL\:
features_1556_p=Databases in zip files are read-only. The performance for some queries will be slower than when using a regular database, because random access in zip files is not supported (only streaming). How much this affects the performance depends on the queries and the data. The database is not read in memory; therefore large databases are supported as well. The same indexes are used as when using a regular database.
features_1557_h2=Graceful Handling of Low Disk Space Situations
features_1558_p=If the database needs more disk space, it calls the database event listener if one is installed. The application may then delete temporary files, or display a message and wait until the user has resolved the problem. To install a listener, run the SQL statement <code 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> (the quotes around the class name are required). See also the <code class\="notranslate">DatabaseEventListener</code> API.
features_1559_h3=Opening a Corrupted Database
features_1560_p=If a database cannot be opened because the boot info (the SQL script that is run at startup) is corrupted, then the database can be opened by specifying a database event listener. The exceptions are logged, but opening the database will continue.
features_1561_h2=Computed Columns / Function Based Index
features_1562_p=Function indexes are not directly supported by this database, but they can be emulated by using computed columns. For example, if an index on the upper-case version of a column is required, create a computed column with the upper-case version of the original column, and create an index for this column\:
features_1563_p=When inserting data, it is not required (and not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table\:
features_1564_h2=Multi-Dimensional Indexes
features_1565_p=A tool is provided to execute efficient multi-dimension (spatial) range queries. This database does not support a specialized spatial index (R-Tree or similar). Instead, the B-Tree index is used. For each record, the multi-dimensional key is converted (mapped) to a single dimensional (scalar) value. This value specifies the location on a space-filling curve.
features_1566_p=Currently, Z-order (also called N-order or Morton-order) is used; Hilbert curve could also be used, but the implementation is more complex. The algorithm to convert the multi-dimensional value is called bit-interleaving. The scalar value is indexed using a B-Tree index (usually using a computed column).
features_1567_p=The method can result in a drastic performance improvement over just using an index on the first column. Depending on the data and number of dimensions, the improvement is usually higher than factor 5. The tool generates a SQL query from a specified multi-dimensional range. The method used is not database dependent, and the tool can easily be ported to other databases. For an example how to use the tool, please have a look at the sample code provided in TestMultiDimension.java.
features_1568_h2=Using Passwords
features_1569_h3=Using Secure Passwords
features_1570_p=Remember that weak passwords can be broken no matter of the encryption and security protocol. Don't use passwords that can be found in a dictionary. Also appending numbers does not make them secure. A way to create good passwords that can be remembered is, take the first letters of a sentence, use upper and lower case characters, and creatively include special characters. Example\:
features_1571_p=i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
features_1572_h3=Passwords\: Using Char Arrays instead of Strings
features_1573_p=Java Strings are immutable objects and cannot be safely 'destroyed' by the application. After creating a String, it will remain in the main memory of the computer at least until it is garbage collected. The garbage collection cannot be controlled by the application, and even if it is garbage collected the data may still remain in memory. It might also be possible that the part of memory containing the password is swapped to disk (because not enough main memory is available).
features_1574_p=An attacker might have access to the swap file of the operating system. It is therefore a good idea to use char arrays instead of Strings to store passwords. Char arrays can be cleared (filled with zeros) after use, and therefore the password will not be stored in the swap file.
features_1575_p=This database supports using char arrays instead of String to pass user and file passwords. The following code can be used to do that\:
features_1576_p=This example requires Java 1.6. When using Swing, use <code class\="notranslate">javax.swing.JPasswordField</code> .
features_1577_h3=Passing the User Name and/or Password in the URL
features_1578_p=Instead of passing the user name as a separate parameter as in <code class\="notranslate">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">Connection conn \= DriverManager. getConnection("jdbc\:h2\:~/test;USER\=sa;PASSWORD\=123");</code> The settings in the URL override the settings passed as a separate parameter.
features_1579_h2=User-Defined Functions and Stored Procedures
features_1580_p=In addition to the built-in functions, this database supports user-defined Java functions. In this database, Java functions can be used as stored procedures as well. A function must be declared (registered) before it can be used. Only static Java methods are supported; both the class and the method must be public. Example Java method\:
features_1581_p=The Java function must be registered in the database by calling <code class\="notranslate">CREATE ALIAS</code> \:
features_1582_p=For a complete sample application, see <code class\="notranslate">src/test/org/h2/samples/Function.java</code> .
features_1583_h3=Function Data Type Mapping
features_1584_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.
features_1585_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> .
features_1586_h3=Functions that require a Connection
features_1587_p=If the first parameter of a Java function is a <code class\="notranslate">java.sql.Connection</code> , then the connection to database is provided. This connection does not need to be closed before returning. When calling the method from within the SQL statement, this connection parameter does not need to be (can not be) specified.
features_1588_h3=Functions throwing an Exception
features_1589_p=If a function throws an exception, then the current statement is rolled back and the exception is thrown to the application.
features_1590_h3=Functions returning a Result Set
features_1591_p=Functions may returns a result set. Such a function can be called with the <code class\="notranslate">CALL</code> statement\:
features_1592_h3=Using SimpleResultSet
features_1593_p=A function can create a result set using the SimpleResultSet tool\:
features_1594_h3=Using a Function as a Table
features_1595_p=A function that returns a result set can be used like a table. However, in this case the function is called at least twice\: first while parsing the statement to collect the column names (with parameters set to null 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> .
features_1596_h2=Triggers
features_1597_p=This database supports Java triggers that are called before or after a row is updated, inserted or deleted. Triggers can be used for complex consistency checks, or to update related data in the database. It is also possible to use triggers to simulate materialized views. For a complete sample application, see <code 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 in the classpath of the database engine (when using the server mode, it must be in the classpath of the server).
features_1598_p=The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database\:
features_1599_p=The trigger can be used to veto a change by throwing a <code class\="notranslate">SQLException</code> .
features_1600_h2=Compacting a Database
features_1601_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 while the database is closed. However in some situations (for example after deleting a lot of data in a database), one sometimes wants to shrink the size of the database (compact a database). Here is a sample function to do this\:
features_1602_p=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 of a database and re-build the database from the script.
features_1603_h2=Cache Settings
features_1604_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> .
features_1605_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> .
features_1606_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 is listed for the data and index file.
fragments_1000_b=Search\:
fragments_1001_td=Highlight keyword(s)
fragments_1002_a=Home
......@@ -1630,40 +1638,42 @@ jaqu_1005_p=Unlike SQL, JaQu can be easily integrated in Java applications. Beca
jaqu_1006_p=JaQu is much smaller than persistence frameworks such as Hibernate. Unlike iBatis and Hibernate, no XML or annotation based configuration is required; instead the configuration (if required at all) is done in pure Java, in the application itself.
jaqu_1007_p=JaQu does not require or contain any data caching mechanism. Like JDBC and iBatis, JaQu provides full control over when and what SQL statements are executed.
jaqu_1008_h3=Restrictions
jaqu_1009_p=Primitive types (eg. boolean, int, long, double) are not supported. Use Boolean, Integer, Long, and Double instead.
jaqu_1009_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.
jaqu_1010_h3=Why in Java?
jaqu_1011_p=Most people use Java in their application. Mixing Java and another language (for example Scala or Groovy) in the same application is complicated\: you would need to split the application and database code.
jaqu_1012_h2=Current State
jaqu_1013_p=Currently, JaQu is only tested with the H2 database. The API may change in future versions. JaQu is not part of the h2 jar file, however the source code is included in H2, under\:
jaqu_1014_li=src/test/org/h2/test/jaqu/* (samples and tests)
jaqu_1015_li=src/tools/org/h2/jaqu/* (framework)
jaqu_1016_h2=Building the JaQu library
jaqu_1017_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> .
jaqu_1018_h2=Requirements
jaqu_1019_p=JaQu requires Java 1.5. Annotations are not need. Currently, JaQu is only tested with the H2 database engine, however in theory it should work with any database that supports the JDBC API.
jaqu_1020_h2=Example Code
jaqu_1021_h2=Configuration
jaqu_1022_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. Example\:
jaqu_1023_p=The method 'define()' 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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
jaqu_1024_h2=Natural Syntax
jaqu_1025_p=The plan is to support more natural (pure Java) syntax in conditions. 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\:
jaqu_1026_h2=Other Ideas
jaqu_1027_p=This project has just been started, and nothing is fixed yet. Some ideas for what to implement are\:
jaqu_1028_li=Support queries on collections (instead of using a database).
jaqu_1029_li=Provide API level compatibility with JPA (so that JaQu can be used as an extension of JPA).
jaqu_1030_li=Internally use a JPA implementation (for example Hibernate) instead of SQL directly.
jaqu_1031_li=Use PreparedStatements and cache them.
jaqu_1032_h2=Related Projects
jaqu_1033_a=Dreamsource ORM
jaqu_1034_a=Empire-db
jaqu_1035_a=JEQUEL\: Java Embedded QUEry Language
jaqu_1036_a=Joist
jaqu_1037_a=JoSQL
jaqu_1038_a=LIQUidFORM
jaqu_1039_a=Quaere (Alias implementation)
jaqu_1040_a=Quaere
jaqu_1041_a=Querydsl
jaqu_1042_a=Squill
jaqu_1014_code=src/test/org/h2/test/jaqu/*
jaqu_1015_li=(samples and tests)
jaqu_1016_code=src/tools/org/h2/jaqu/*
jaqu_1017_li=(framework)
jaqu_1018_h2=Building the JaQu library
jaqu_1019_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> .
jaqu_1020_h2=Requirements
jaqu_1021_p=JaQu requires Java 1.5. Annotations are not need. Currently, JaQu is only tested with the H2 database engine, however in theory it should work with any database that supports the JDBC API.
jaqu_1022_h2=Example Code
jaqu_1023_h2=Configuration
jaqu_1024_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. Example\:
jaqu_1025_p=The method <code class\="notranslate">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). Because the definition is written in regular Java, the configuration can depend on the environment. This is not possible using annotations. Unlike XML mapping configuration, the configuration is integrated in the class itself.
jaqu_1026_h2=Natural Syntax
jaqu_1027_p=The plan is to support more natural (pure Java) syntax in conditions. 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\:
jaqu_1028_h2=Other Ideas
jaqu_1029_p=This project has just been started, and nothing is fixed yet. Some ideas for what to implement are\:
jaqu_1030_li=Support queries on collections (instead of using a database).
jaqu_1031_li=Provide API level compatibility with JPA (so that JaQu can be used as an extension of JPA).
jaqu_1032_li=Internally use a JPA implementation (for example Hibernate) instead of SQL directly.
jaqu_1033_li=Use PreparedStatements and cache them.
jaqu_1034_h2=Related Projects
jaqu_1035_a=Dreamsource ORM
jaqu_1036_a=Empire-db
jaqu_1037_a=JEQUEL\: Java Embedded QUEry Language
jaqu_1038_a=Joist
jaqu_1039_a=JoSQL
jaqu_1040_a=LIQUidFORM
jaqu_1041_a=Quaere (Alias implementation)
jaqu_1042_a=Quaere
jaqu_1043_a=Querydsl
jaqu_1044_a=Squill
license_1000_h1=License
license_1001_h2=Summary and License FAQ
license_1002_p=H2 is dual licensed and available under a modified version of the MPL 1.1 ( <a href\="http\://www.mozilla.org/MPL">Mozilla Public License</a> ) or under the (unmodified) EPL 1.0 ( <a href\="http\://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License</a> ). The changes to the MPL are
......
......@@ -297,10 +297,15 @@ java org.h2.test.TestAll timer
/*
translate button should be disabled by default because it is slow.
replace class="n" with class="notranslate" for website
documentation: rolling review at features (alphabetically)
documentation: rolling review at tutorial.html (alphabetically)
<code class="notranslate"></code>
check no space http: or https:
check space' and 'space
check spaceNULL and NULLspace
tool...
mvcc merge problem
......
......@@ -615,4 +615,4 @@ linkage superfluous disallow scoop moebius inputs copilot dmoebius leod jenkov
jakob poker docware peter unstable measurable scramble reissued recreation
scrambling distinguish official unofficial distinguishable overwrites lastval
notranslate vince bonfanti alphabetically sysdummy sysibm activation
deactivation
\ No newline at end of file
deactivation concatenating reproducing
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论