*7 Derby only supports updatable result sets if the query is not sorted.
*7 Derby only supports updatable result sets if the query is not sorted.
@features_1265_p
@features_1265_p
*8 Derby and HSQLDB don't support standard compliant information schema tables. *9 H2 supports row level locks when using multi version concurrency.
*8 Derby and HSQLDB don't support standard compliant information schema tables.
@features_1266_h3
@features_1266_p
*9 H2 supports row level locks when using multi version concurrency.
@features_1267_h3
Derby and HSQLDB
Derby and HSQLDB
@features_1267_p
@features_1268_p
After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
@features_1268_h3
@features_1269_h3
DaffodilDb and One$Db
DaffodilDb and One$Db
@features_1269_p
@features_1270_p
It looks like the development of this database has stopped. The last release was February 2006.
It looks like the development of this database has stopped. The last release was February 2006.
@features_1270_h3
@features_1271_h3
McKoi
McKoi
@features_1271_p
@features_1272_p
It looks like the development of this database has stopped. The last release was August 2004
It looks like the development of this database has stopped. The last release was August 2004
@features_1272_h2
@features_1273_h2
H2 in Use
H2 in Use
@features_1273_p
@features_1274_p
For a list of applications that work with or use H2, see: <a href="links.html">Links</a> .
For a list of applications that work with or use H2, see: <a href="links.html">Links</a> .
@features_1274_h2
@features_1275_h2
Connection Modes
Connection Modes
@features_1275_p
@features_1276_p
The following connection modes are supported:
The following connection modes are supported:
@features_1276_li
Embedded mode (local connections using JDBC)
@features_1277_li
@features_1277_li
Remote mode (remote connections using JDBC or ODBC over TCP/IP)
Embedded mode (local connections using JDBC)
@features_1278_li
@features_1278_li
Server mode (remote connections using JDBC or ODBC over TCP/IP)
@features_1279_li
Mixed mode (local and remote connections at the same time)
Mixed mode (local and remote connections at the same time)
@features_1279_h3
@features_1280_h3
Embedded Mode
Embedded Mode
@features_1280_p
@features_1281_p
In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1281_h3
@features_1282_h3
Remote Mode
Server Mode
@features_1282_p
@features_1283_p
When using the remote mode (sometimes called server mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine (or on another computer). Many applications can connect to the same database at the same time. The remote mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
When using the server mode (sometimes called remote mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine, or on another computer. Many applications can connect to the same database at the same time. The server mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1283_h3
@features_1284_h3
Mixed Mode
Mixed Mode
@features_1284_p
@features_1285_p
The mixed mode is a combination of the embedded and the remote mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The embedded connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower. All clients that want to connect to the database (no matter if it's an embedded or remote connection) can do so using the exact same database URL.
The mixed mode is a combination of the embedded and the server mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The local connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower.
@features_1285_h2
@features_1286_p
The server can be started and stopped from within the application (using the server API), or automatically (automatic mixed mode). When using the <a href="#auto_mixed_mode">automatic mixed mode</a> , all clients that want to connect to the database (no matter if it's an local or remote connection) can do so using the exact same database URL.
@features_1287_h2
Database URL Overview
Database URL Overview
@features_1286_p
@features_1288_p
This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
The database URL for connecting to a local database is <code>jdbc:h2:[file:][<path>]<databaseName></code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in: jdbc:h2:~/test.
The database URL for connecting to a local database is <code>jdbc:h2:[file:][<path>]<databaseName></code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in: jdbc:h2:~/test.
@features_1349_h2
@features_1353_h2
Memory-Only Databases
Memory-Only Databases
@features_1350_p
@features_1354_p
For certain use cases (for example: rapid prototyping, testing, high performance operations, read-only databases), it may not be required to persist (changes to) the data at all. This database supports the memory-only mode, where the data is not persisted.
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_1351_p
@features_1355_p
In some cases, only one connection to a memory-only database is required. This means the database to be opened is private. In this case, the database URL is <code>jdbc:h2:mem:</code> Opening two connections within the same virtual machine means opening two different (private) databases.
In some cases, only one connection to a memory-only database is required. This means the database to be opened is private. In this case, the database URL is <code>jdbc:h2:mem:</code> Opening two connections within the same virtual machine means opening two different (private) databases.
@features_1352_p
@features_1356_p
Sometimes multiple connections to the same memory-only database are required. In this case, the database URL must include a name. Example: <code>jdbc:h2:mem:db1</code> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
Sometimes multiple connections to the same memory-only database are required. In this case, the database URL must include a name. Example: <code>jdbc:h2:mem:db1</code> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
@features_1353_p
@features_1357_p
It is also possible to access a memory-only database remotely (or from multiple processes in the same machine) using TCP/IP or SSL/TLS. An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code> (using private database remotely is also possible).
It is also possible to access a memory-only database remotely (or from multiple processes in the same machine) using TCP/IP or SSL/TLS. An example database URL is: <code>jdbc:h2:tcp://localhost/mem:db1</code> (using private database remotely is also possible).
@features_1354_p
@features_1358_p
By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
@features_1355_h2
@features_1359_h2
Database Files Encryption
Database Files Encryption
@features_1356_p
@features_1360_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.
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_1357_h3
@features_1361_h3
Creating a New Database with File Encryption
Creating a New Database with File Encryption
@features_1358_p
@features_1362_p
By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
@features_1359_h3
@features_1363_h3
Connecting to an Encrypted Database
Connecting to an Encrypted Database
@features_1360_p
@features_1364_p
The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database:
The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database:
@features_1361_h3
@features_1365_h3
Encrypting or Decrypting a Database
Encrypting or Decrypting a Database
@features_1362_p
@features_1366_p
If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES:
If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES:
@features_1363_h2
@features_1367_h2
Database File Locking
Database File Locking
@features_1364_p
@features_1368_p
Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
@features_1365_p
@features_1369_p
The following file locking methods are implemented:
The following file locking methods are implemented:
@features_1366_li
@features_1370_li
The default method is 'file' and uses a watchdog thread to protect the database file. The watchdog reads the lock file each second.
The default method is 'file' and uses a watchdog thread to protect the database file. The watchdog reads the lock file each second.
@features_1367_li
@features_1371_li
The second method is 'socket' and opens a server socket. The socket method does not require reading the lock file every second. The socket method should only be used if the database files are only accessed by the one (and always the same) computer.
The second method is 'socket' and opens a server socket. The socket method does not require reading the lock file every second. The socket method should only be used if the database files are only accessed by the one (and always the same) computer.
@features_1368_li
@features_1372_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.
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_1369_p
@features_1373_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 'FILE_LOCK'. The following code opens the database with the 'socket' locking method:
@features_1370_p
@features_1374_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:
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_1371_p
@features_1375_p
For more information about the algorithms please see in Advanced Topics under File Locking Protocol.
For more information about the algorithms please see in Advanced Topics under File Locking Protocol.
@features_1372_h2
@features_1376_h2
Opening a Database Only if it Already Exists
Opening a Database Only if it Already Exists
@features_1373_p
@features_1377_p
By default, when an application calls <code>DriverManager.getConnection(url,...)</code> and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new database, and only open the database if it already exists. This can be done by adding <code>;ifexists=true</code> to the URL. In this case, if the database does not already exist, an exception is thrown when trying to connect. The connection only succeeds when the database already exists. The complete URL may look like this:
By default, when an application calls <code>DriverManager.getConnection(url,...)</code> and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new database, and only open the database if it already exists. This can be done by adding <code>;ifexists=true</code> to the URL. In this case, if the database does not already exist, an exception is thrown when trying to connect. The connection only succeeds when the database already exists. The complete URL may look like this:
@features_1374_h2
@features_1378_h2
Closing the Database
Closing the Database
@features_1375_h3
@features_1379_h3
Delayed Database Closing
Delayed Database Closing
@features_1376_p
@features_1380_p
Usually, the database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible leave the connection open. The automatic closing of the database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY <seconds>. The seconds specifies the number of seconds to keep a database open after the last connection to it was closed. For example the following statement will keep the database open for 10 seconds:
Usually, the database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible leave the connection open. The automatic closing of the database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY <seconds>. The seconds specifies the number of seconds to keep a database open after the last connection to it was closed. For example the following statement will keep the database open for 10 seconds:
@features_1377_p
@features_1381_p
The value -1 means the database is never closed automatically. The value 0 is the default and means the database is closed when the last connection is closed. This setting is persistent and can be set by an administrator only. It is possible to set the value in the database URL: <code>jdbc:h2:~/test;DB_CLOSE_DELAY=10</code> .
The value -1 means the database is never closed automatically. The value 0 is the default and means the database is closed when the last connection is closed. This setting is persistent and can be set by an administrator only. It is possible to set the value in the database URL: <code>jdbc:h2:~/test;DB_CLOSE_DELAY=10</code> .
@features_1378_h3
@features_1382_h3
Don't Close the Database when the VM Exits
Don't Close the Database when the VM Exits
@features_1379_p
@features_1383_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. This is done using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). 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:
By default, a database is closed when the last connection is closed. However, if it is never closed, the database is closed when the virtual machine exits normally. This is done using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). 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_1380_h2
@features_1384_h2
Log Index Changes
Log Index Changes
@features_1381_p
@features_1385_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 jdbc:h2:~/test;LOG=2 This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
Usually, changes to the index file are not logged for performance. If the index file is corrupt or missing when opening a database, it is re-created from the data. The index file can get corrupt when the database is not shut down correctly, because of power failure or abnormal program termination. In some situations, for example when using very large databases (over a few hundred MB), re-creating the index file takes very long. In these situations it may be better to log changes to the index file, so that recovery from a corrupted index file is fast. To enable log index changes, add LOG=2 to the URL, as in jdbc:h2:~/test;LOG=2 This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
@features_1382_h2
@features_1386_h2
Ignore Unknown Settings
Ignore Unknown Settings
@features_1383_p
@features_1387_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 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_h2
@features_1388_h2
Changing Other Settings when Opening a Connection
Changing Other Settings when Opening a Connection
@features_1385_p
@features_1389_p
In addition to the settings already described (cipher, file_lock, ifexists, user, password), other database settings can be passed in the database URL. Adding <code>setting=value</code> at the end of an URL is the same as executing the statement <code>SET setting value</code> just after connecting. For a list of settings supported by this database please see the SQL grammar documentation.
In addition to the settings already described (cipher, file_lock, ifexists, user, password), other database settings can be passed in the database URL. Adding <code>setting=value</code> at the end of an URL is the same as executing the statement <code>SET setting value</code> just after connecting. For a list of settings supported by this database please see the SQL grammar documentation.
@features_1386_h2
@features_1390_h2
Custom File Access Mode
Custom File Access Mode
@features_1387_p
@features_1391_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 '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
@features_1392_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.
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_1389_h2
@features_1393_h2
Multiple Connections
Multiple Connections
@features_1390_h3
@features_1394_h3
Opening Multiple Databases at the Same Time
Opening Multiple Databases at the Same Time
@features_1391_p
@features_1395_p
An application can open multiple databases at the same time, including multiple connections to the same database. The number of open database is only limited by the memory available.
An application can open multiple databases at the same time, including multiple connections to the same database. The number of open database is only limited by the memory available.
@features_1392_h3
@features_1396_h3
Multiple Connections to the Same Database: Client/Server
Multiple Connections to the Same Database: Client/Server
@features_1393_p
@features_1397_p
If you want to access the same database at the same time from different processes or computers, you need to use the client / server mode. In this case, one process acts as the server, and the other processes (that could reside on other computers as well) connect to the server via TCP/IP (or SSL/TLS over TCP/IP for improved security).
If you want to access the same database at the same time from different processes or computers, you need to use the client / server mode. In this case, one process acts as the server, and the other processes (that could reside on other computers as well) connect to the server via TCP/IP (or SSL/TLS over TCP/IP for improved security).
@features_1394_h3
@features_1398_h3
Multithreading Support
Multithreading Support
@features_1395_p
@features_1399_p
This database is multithreading-safe. That means, if an application is multi-threaded, it does not need o worry about synchronizing the access to the database. Internally, most requests to the same database are synchronized. That means an application can use multiple threads accessing the same database at the same time, however if one thread executes a long running query, the other threads need to wait.
This database is multithreading-safe. That means, if an application is multi-threaded, it does not need o worry about synchronizing the access to the database. Internally, most requests to the same database are synchronized. That means an application can use multiple threads accessing the same database at the same time, however if one thread executes a long running query, the other threads need to wait.
@features_1396_h3
@features_1400_h3
Locking, Lock-Timeout, Deadlocks
Locking, Lock-Timeout, Deadlocks
@features_1397_p
@features_1401_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). If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
The database uses table level locks to give each connection a consistent state of the data. There are two kinds of locks: read locks (shared locks) and write locks (exclusive locks). If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
@features_1398_p
@features_1402_p
Usually, SELECT statement will generate read locks. This includes subqueries. Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data, using the statement SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. Here is an overview on what statements generate what type of lock:
Usually, SELECT statement will generate read locks. This includes subqueries. Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data, using the statement SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. Here is an overview on what statements generate what type of lock:
@features_1399_th
@features_1403_th
Type of Lock
Type of Lock
@features_1400_th
@features_1404_th
SQL Statement
SQL Statement
@features_1401_td
@features_1405_td
Read
Read
@features_1402_td
@features_1406_td
SELECT * FROM TEST
SELECT * FROM TEST
@features_1403_td
@features_1407_td
CALL SELECT MAX(ID) FROM TEST
CALL SELECT MAX(ID) FROM TEST
@features_1404_td
@features_1408_td
SCRIPT
SCRIPT
@features_1405_td
@features_1409_td
Write
Write
@features_1406_td
@features_1410_td
SELECT * FROM TEST WHERE 1=0 FOR UPDATE
SELECT * FROM TEST WHERE 1=0 FOR UPDATE
@features_1407_td
@features_1411_td
Write
Write
@features_1408_td
@features_1412_td
INSERT INTO TEST VALUES(1, 'Hello')
INSERT INTO TEST VALUES(1, 'Hello')
@features_1409_td
@features_1413_td
INSERT INTO TEST SELECT * FROM TEST
INSERT INTO TEST SELECT * FROM TEST
@features_1410_td
@features_1414_td
UPDATE TEST SET NAME='Hi'
UPDATE TEST SET NAME='Hi'
@features_1411_td
@features_1415_td
DELETE FROM TEST
DELETE FROM TEST
@features_1412_td
@features_1416_td
Write
Write
@features_1413_td
@features_1417_td
ALTER TABLE TEST ...
ALTER TABLE TEST ...
@features_1414_td
@features_1418_td
CREATE INDEX ... ON TEST ...
CREATE INDEX ... ON TEST ...
@features_1415_td
@features_1419_td
DROP INDEX ...
DROP INDEX ...
@features_1416_p
@features_1420_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 <milliseconds>. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT <milliseconds>. 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 SET LOCK_TIMEOUT <milliseconds>. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT <milliseconds>. The default lock timeout is persistent.
@features_1417_h2
@features_1421_h2
Database File Layout
Database File Layout
@features_1418_p
@features_1422_p
There are a number of files created for persistent databases. Other than some databases, not every table and/or index is stored in its own file. Instead, usually only the following files are created: A data file, an index file, a log file, and a database lock file (exists only while the database is in use). In addition to that, a file is created for each large object (CLOB/BLOB), a file for each linear index, and temporary files for large result sets. Then the command SCRIPT can create script files. If the database trace option is enabled, trace files are created. The following files can be created by the database:
There are a number of files created for persistent databases. Other than some databases, not every table and/or index is stored in its own file. Instead, usually only the following files are created: A data file, an index file, a log file, and a database lock file (exists only while the database is in use). In addition to that, a file is created for each large object (CLOB/BLOB), a file for each linear index, and temporary files for large result sets. Then the command SCRIPT can create script files. If the database trace option is enabled, trace files are created. The following files can be created by the database:
@features_1419_th
@features_1423_th
File Name
File Name
@features_1420_th
@features_1424_th
Description
Description
@features_1421_th
@features_1425_th
Number of Files
Number of Files
@features_1422_td
@features_1426_td
test.data.db
test.data.db
@features_1423_td
@features_1427_td
Data file
Data file
@features_1424_td
@features_1428_td
Contains the data for all tables
Contains the data for all tables
@features_1425_td
@features_1429_td
Format: <database>.data.db
Format: <database>.data.db
@features_1426_td
@features_1430_td
1 per database
1 per database
@features_1427_td
@features_1431_td
test.index.db
test.index.db
@features_1428_td
@features_1432_td
Index file
Index file
@features_1429_td
@features_1433_td
Contains the data for all (btree) indexes
Contains the data for all (btree) indexes
@features_1430_td
@features_1434_td
Format: <database>.index.db
Format: <database>.index.db
@features_1431_td
@features_1435_td
1 per database
1 per database
@features_1432_td
@features_1436_td
test.0.log.db
test.0.log.db
@features_1433_td
@features_1437_td
Log file
Log file
@features_1434_td
@features_1438_td
The log file is used for recovery
The log file is used for recovery
@features_1435_td
@features_1439_td
Format: <database>.<id>.log.db
Format: <database>.<id>.log.db
@features_1436_td
@features_1440_td
0 or more per database
0 or more per database
@features_1437_td
@features_1441_td
test.lock.db
test.lock.db
@features_1438_td
@features_1442_td
Database lock file
Database lock file
@features_1439_td
@features_1443_td
Exists only if the database is open
Exists only if the database is open
@features_1440_td
@features_1444_td
Format: <database>.lock.db
Format: <database>.lock.db
@features_1441_td
@features_1445_td
1 per database
1 per database
@features_1442_td
@features_1446_td
test.trace.db
test.trace.db
@features_1443_td
@features_1447_td
Trace file
Trace file
@features_1444_td
@features_1448_td
Contains trace information
Contains trace information
@features_1445_td
@features_1449_td
Format: <database>.trace.db
Format: <database>.trace.db
@features_1446_td
@features_1450_td
If the file is too big, it is renamed to <database>.trace.db.old
If the file is too big, it is renamed to <database>.trace.db.old
Database name and location are not stored inside the database names.
Database name and location are not stored inside the database names.
@features_1465_p
@features_1469_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).
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_1466_p
@features_1470_p
As there is no platform specific data in the files, they can be moved to other operating systems without problems.
As there is no platform specific data in the files, they can be moved to other operating systems without problems.
@features_1467_h3
@features_1471_h3
Backup
Backup
@features_1468_p
@features_1472_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.
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_1469_p
@features_1473_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 SCRIPT can be used.
@features_1470_h2
@features_1474_h2
Logging and Recovery
Logging and Recovery
@features_1471_p
@features_1475_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.
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_1472_p
@features_1476_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.
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_1473_p
@features_1477_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.
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_1474_p
@features_1478_p
If the database file is corrupted, because the checksum of a record does not match (for example, if the file was edited with another application), the database can be opened in recovery mode. In this case, errors in the database are logged but not thrown. The database should be backed up to a script and re-built as soon as possible. To open the database in the recovery mode, use a database URL must contain RECOVER=1, as in jdbc:h2:~/test;RECOVER=1. Indexes are rebuilt in this case, and the summary (object allocation table) is not read in this case, so opening the database takes longer.
If the database file is corrupted, because the checksum of a record does not match (for example, if the file was edited with another application), the database can be opened in recovery mode. In this case, errors in the database are logged but not thrown. The database should be backed up to a script and re-built as soon as possible. To open the database in the recovery mode, use a database URL must contain RECOVER=1, as in jdbc:h2:~/test;RECOVER=1. Indexes are rebuilt in this case, and the summary (object allocation table) is not read in this case, so opening the database takes longer.
@features_1475_h2
@features_1479_h2
Compatibility
Compatibility
@features_1476_p
@features_1480_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:
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_1477_p
@features_1481_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: jdbc:h2:~/test;IGNORECASE=TRUE).
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: jdbc:h2:~/test;IGNORECASE=TRUE).
@features_1478_h3
@features_1482_h3
Compatibility Modes
Compatibility Modes
@features_1479_p
@features_1483_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 difference to the regular mode:
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 difference to the regular mode:
@features_1480_h3
@features_1484_h3
DB2 Compatibility Mode
DB2 Compatibility Mode
@features_1481_p
@features_1485_p
To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
@features_1482_li
@features_1486_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1483_li
@features_1487_li
Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
@features_1484_h3
@features_1488_h3
Derby Compatibility Mode
Derby Compatibility Mode
@features_1485_p
@features_1489_p
To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
@features_1486_li
@features_1490_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1487_li
@features_1491_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1488_h3
@features_1492_h3
HSQLDB Compatibility Mode
HSQLDB Compatibility Mode
@features_1489_p
@features_1493_p
To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
@features_1490_li
@features_1494_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1491_li
@features_1495_li
When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
@features_1492_li
@features_1496_li
Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
@features_1493_li
@features_1497_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1494_h3
@features_1498_h3
MS SQL Server Compatibility Mode
MS SQL Server Compatibility Mode
@features_1495_p
@features_1499_p
To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
@features_1496_li
@features_1500_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1497_li
@features_1501_li
Identifiers may be quoted using square brackets as in [Test].
Identifiers may be quoted using square brackets as in [Test].
@features_1498_li
@features_1502_li
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1499_h3
@features_1503_h3
MySQL Compatibility Mode
MySQL Compatibility Mode
@features_1500_p
@features_1504_p
To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
@features_1501_li
@features_1505_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.
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_1502_li
@features_1506_li
Creating indexes in the CREATE TABLE statement should be supported.
Creating indexes in the CREATE TABLE statement should be supported.
@features_1503_li
@features_1507_li
The identifiers should be returned in lower case.
The identifiers should be returned in lower case.
@features_1504_li
@features_1508_li
When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
@features_1505_h3
@features_1509_h3
Oracle Compatibility Mode
Oracle Compatibility Mode
@features_1506_p
@features_1510_p
To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
@features_1507_li
@features_1511_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1508_li
@features_1512_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.
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_1509_h3
@features_1513_h3
PostgreSQL Compatibility Mode
PostgreSQL Compatibility Mode
@features_1510_p
@features_1514_p
To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
@features_1511_li
@features_1515_li
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1512_li
@features_1516_li
Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
@features_1513_li
@features_1517_li
When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
@features_1514_li
@features_1518_li
The system columns 'CTID' and 'OID' should be supported.
The system columns 'CTID' and 'OID' should be supported.
@features_1515_h2
@features_1519_h2
Auto-Reconnect
Auto-Reconnect
@features_1516_p
@features_1520_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.
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_1517_p
@features_1521_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.
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_1518_h2
@features_1522_h2
Automatic Mixed Mode
Automatic Mixed Mode
@features_1519_p
@features_1523_p
Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
@features_1520_p
@features_1524_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.
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_1521_p
@features_1525_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).
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_1522_p
@features_1526_p
This mode has three disadvantages: All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.
This mode has three disadvantages: All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.
@features_1523_p
@features_1527_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).
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_1524_h2
@features_1528_h2
Using the Trace Options
Using the Trace Options
@features_1525_p
@features_1529_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:
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_1526_li
@features_1530_li
Trace to System.out and/or a file
Trace to System.out and/or a file
@features_1527_li
@features_1531_li
Support for trace levels OFF, ERROR, INFO, and DEBUG
Support for trace levels OFF, ERROR, INFO, and DEBUG
@features_1528_li
@features_1532_li
The maximum size of the trace file can be set
The maximum size of the trace file can be set
@features_1529_li
@features_1533_li
The Java code generation is possible
The Java code generation is possible
@features_1530_li
@features_1534_li
Trace can be enabled at runtime by manually creating a file
Trace can be enabled at runtime by manually creating a file
@features_1531_h3
@features_1535_h3
Trace Options
Trace Options
@features_1532_p
@features_1536_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:
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_1533_p
@features_1537_p
The trace level can be changed at runtime by executing the SQL command <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for System.out tracing) or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing). Example:
The trace level can be changed at runtime by executing the SQL command <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for System.out tracing) or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing). Example:
@features_1534_h3
@features_1538_h3
Setting the Maximum Size of the Trace File
Setting the Maximum Size of the Trace File
@features_1535_p
@features_1539_p
When using a high trace level, the trace file can get very big quickly. The size of the file can be limited by executing the SQL statement <code>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . If the log file exceeds the limit, the file is renamed to .old and a new file is created. If another .old file exists, it is deleted. The default setting is 16 MB. Example:
When using a high trace level, the trace file can get very big quickly. The size of the file can be limited by executing the SQL statement <code>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . If the log file exceeds the limit, the file is renamed to .old and a new file is created. If another .old file exists, it is deleted. The default setting is 16 MB. Example:
@features_1536_h3
@features_1540_h3
Java Code Generation
Java Code Generation
@features_1537_p
@features_1541_p
When setting the trace level to INFO or DEBUG, Java source code is generated as well, so that problem can be reproduced more easily. The trace file looks like this:
When setting the trace level to INFO or DEBUG, Java source code is generated as well, so that problem can be reproduced more easily. The trace file looks like this:
@features_1538_p
@features_1542_p
You need to filter out the lines without /**/ to get the Java source code. In Windows, a simple way to do that is:
You need to filter out the lines without /**/ to get the Java source code. In Windows, a simple way to do that is:
@features_1539_p
@features_1543_p
Afterwards, you need to complete the file Trace.java before it can be compiled, for example with:
Afterwards, you need to complete the file Trace.java before it can be compiled, for example with:
@features_1540_p
@features_1544_p
Also, the user name and password needs to be set, because they are not listed in the trace file.
Also, the user name and password needs to be set, because they are not listed in the trace file.
@features_1541_h2
@features_1545_h2
Using Other Logging APIs
Using Other Logging APIs
@features_1542_p
@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 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.
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_1543_a
@features_1547_a
SLF4J
SLF4J
@features_1544_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), JDK 1.4 logging, x4juli, and Simple Log.
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), JDK 1.4 logging, x4juli, and Simple Log.
@features_1545_p
@features_1549_p
To enable SLF4J, set the file trace level to 4 in the database URL:
To enable SLF4J, set the file trace level to 4 in the database URL:
@features_1546_p
@features_1550_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 in the file <database>.trace.db for error messages.
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 in the file <database>.trace.db for error messages.
@features_1547_h2
@features_1551_h2
Read Only Databases
Read Only Databases
@features_1548_p
@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 SELECT 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 a database is read-only: By calling Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
If the database files are read-only, then the database is read-only as well. It is not possible to create new tables, add or modify data in this database. Only SELECT statements are allowed. To create a read-only database, close the database so that the log file 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 a database is read-only: By calling Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
@features_1549_h2
@features_1553_h2
Read Only Databases in Zip or Jar File
Read Only Databases in Zip or Jar File
@features_1550_p
@features_1554_p
To create a read-only database in a zip, 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:
To create a read-only database in a zip, 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_1551_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:
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_1552_p
@features_1556_p
Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database.
Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database.
@features_1553_h2
@features_1557_h2
Graceful Handling of Low Disk Space Situations
Graceful Handling of Low Disk Space Situations
@features_1554_p
@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 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.
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_1555_h3
@features_1559_h3
Opening a Corrupted Database
Opening a Corrupted Database
@features_1556_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.
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_1557_h2
@features_1561_h2
Computed Columns / Function Based Index
Computed Columns / Function Based Index
@features_1558_p
@features_1562_p
Function indexes are not directly supported by this database, but they can be easily emulated by using computed columns. For example, if an index on the upper-case version of a column is required, just create a computed column with the upper-case version of the original column, and index this column:
Function indexes are not directly supported by this database, but they can be easily emulated by using computed columns. For example, if an index on the upper-case version of a column is required, just create a computed column with the upper-case version of the original column, and index this column:
@features_1559_p
@features_1563_p
When inserting data, it is not required (better: not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table:
When inserting data, it is not required (better: not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table:
@features_1560_h2
@features_1564_h2
Multi-Dimensional Indexes
Multi-Dimensional Indexes
@features_1561_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.
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_1562_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).
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_1563_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.
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_1564_h2
@features_1568_h2
Using Passwords
Using Passwords
@features_1565_h3
@features_1569_h3
Using Secure Passwords
Using Secure Passwords
@features_1566_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:
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_1567_p
@features_1571_p
i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
@features_1568_h3
@features_1572_h3
Passwords: Using Char Arrays instead of Strings
Passwords: Using Char Arrays instead of Strings
@features_1569_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).
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_1570_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.
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_1571_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:
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_1572_p
@features_1576_p
In this example, the password is hard code in the application, which is not secure of course. However, Java Swing supports a way to get passwords using a char array (JPasswordField).
In this example, the password is hard code in the application, which is not secure of course. However, Java Swing supports a way to get passwords using a char array (JPasswordField).
@features_1573_h3
@features_1577_h3
Passing the User Name and/or Password in the URL
Passing the User Name and/or Password in the URL
@features_1574_p
@features_1578_p
Instead of passing the user name as a separate parameter as in <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself: <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter.
Instead of passing the user name as a separate parameter as in <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself: <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter.
@features_1575_h2
@features_1579_h2
User-Defined Functions and Stored Procedures
User-Defined Functions and Stored Procedures
@features_1576_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:
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_1577_p
@features_1581_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 CREATE ALIAS:
@features_1578_p
@features_1582_p
For a complete sample application, see src/test/org/h2/samples/Function.java.
For a complete sample application, see src/test/org/h2/samples/Function.java.
@features_1579_h3
@features_1583_h3
Function Data Type Mapping
Function Data Type Mapping
@features_1580_p
@features_1584_p
Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. In this case, the value NULL is used as the result. If the function should be called in this case, you need to use 'java.lang.Integer' instead of 'int'.
Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. In this case, the value NULL is used as the result. If the function should be called in this case, you need to use 'java.lang.Integer' instead of 'int'.
@features_1581_h3
@features_1585_h3
Functions that require a Connection
Functions that require a Connection
@features_1582_p
@features_1586_p
If the first parameter in a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning.
If the first parameter in a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning.
@features_1583_h3
@features_1587_h3
Functions throwing an Exception
Functions throwing an Exception
@features_1584_p
@features_1588_p
If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
@features_1585_h3
@features_1589_h3
Functions returning a Result Set
Functions returning a Result Set
@features_1586_p
@features_1590_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 CALL statement:
@features_1587_h3
@features_1591_h3
Using SimpleResultSet
Using SimpleResultSet
@features_1588_p
@features_1592_p
A function that returns a result set can create this result set from scratch using the SimpleResultSet tool:
A function that returns a result set can create this result set from scratch using the SimpleResultSet tool:
@features_1589_h3
@features_1593_h3
Using a Function as a Table
Using a Function as a Table
@features_1590_p
@features_1594_p
A function returning a result set can be like a table. However, in this case the function is called at least twice: First while parsing the statement to collect the column names (with parameters set to null where not known at compile time). And then, while executing the statement to get the data (may be repeatedly if this is a join). If the function is called just to get the column list, the URL of the connection passed to the function is jdbc:columnlist:connection. Otherwise, the URL of the connection is jdbc:default:connection.
A function returning a result set can be like a table. However, in this case the function is called at least twice: First while parsing the statement to collect the column names (with parameters set to null where not known at compile time). And then, while executing the statement to get the data (may be repeatedly if this is a join). If the function is called just to get the column list, the URL of the connection passed to the function is jdbc:columnlist:connection. Otherwise, the URL of the connection is jdbc:default:connection.
@features_1591_h2
@features_1595_h2
Triggers
Triggers
@features_1592_p
@features_1596_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:
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:
@features_1593_p
@features_1597_p
The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database:
The connection can be used to query or update data in other tables. The trigger then needs to be defined in the database:
@features_1594_p
@features_1598_p
The trigger can be used to veto a change, by throwing a SQL Exception.
The trigger can be used to veto a change, by throwing a SQL Exception.
@features_1595_h2
@features_1599_h2
Compacting a Database
Compacting a Database
@features_1596_p
@features_1600_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:
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_1597_p
@features_1601_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.
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_1598_h2
@features_1602_h2
Cache Settings
Cache Settings
@features_1599_p
@features_1603_p
The database keeps most frequently used data and index pages in the main memory. The amount of memory used for caching can be changed using the setting CACHE_SIZE. This setting can be set in the database connection URL (jdbc:h2:~/test;CACHE_SIZE=131072), or it can be changed at runtime using SET CACHE_SIZE size.
The database keeps most frequently used data and index pages in the main memory. The amount of memory used for caching can be changed using the setting CACHE_SIZE. This setting can be set in the database connection URL (jdbc:h2:~/test;CACHE_SIZE=131072), or it can be changed at runtime using SET CACHE_SIZE size.
@features_1600_p
@features_1604_p
This database supports two cache page replacement algorithms: LRU (the default) and 2Q. For LRU, the pages that were least frequently used are removed from the cache if it becomes full. The 2Q algorithm is a bit more complicated: basically two queues are used. The 2Q algorithm is more resistant to table scans, however the overhead is a bit higher compared to the LRU. To use the cache algorithm 2Q, use a database URL of the form jdbc:h2:~/test;CACHE_TYPE=TQ. The cache algorithm cannot be changed once the database is open.
This database supports two cache page replacement algorithms: LRU (the default) and 2Q. For LRU, the pages that were least frequently used are removed from the cache if it becomes full. The 2Q algorithm is a bit more complicated: basically two queues are used. The 2Q algorithm is more resistant to table scans, however the overhead is a bit higher compared to the LRU. To use the cache algorithm 2Q, use a database URL of the form jdbc:h2:~/test;CACHE_TYPE=TQ. The cache algorithm cannot be changed once the database is open.
@features_1601_p
@features_1605_p
To get information about page reads and writes, and the current caching algorithm in use, call SELECT * FROM INFORMATION_SCHEMA.SETTINGS. The number of pages read / written is listed for the data and index file.
To get information about page reads and writes, and the current caching algorithm in use, call SELECT * FROM INFORMATION_SCHEMA.SETTINGS. The number of pages read / written is listed for the data and index file.
#Web-based Console application (translated to many languages) with autocomplete #Webベースのコンソールアプリケーション (英語、ドイツ語、部分的にフランス語とスペイン語) が自動完備
@features_1080_li
@features_1080_li
データベースはSQLスクリプトファイルを生成
データベースはSQLスクリプトファイルを生成
@features_1081_li
@features_1081_li
データファイルのコンテンツを移動することができるリカバリーツールを含む
#Contains a recovery tool that can dump the contents of the database #データファイルのコンテンツを移動することができるリカバリーツールを含む
@features_1082_li
@features_1082_li
#Support for variables (for example to calculate running totals)
#Support for variables (for example to calculate running totals)
...
@@ -3412,1014 +3412,1026 @@ ODBCドライバ
...
@@ -3412,1014 +3412,1026 @@ ODBCドライバ
#*7 Derby only supports updatable result sets if the query is not sorted.
#*7 Derby only supports updatable result sets if the query is not sorted.
@features_1265_p
@features_1265_p
#*8 Derby and HSQLDB don't support standard compliant information schema tables. *9 H2 supports row level locks when using multi version concurrency.
#*8 Derby and HSQLDB don't support standard compliant information schema tables.
@features_1266_h3
@features_1266_p
#*9 H2 supports row level locks when using multi version concurrency.
@features_1267_h3
DerbyとHSQLDB
DerbyとHSQLDB
@features_1267_p
@features_1268_p
#After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
#After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
@features_1268_h3
@features_1269_h3
DaffodilDbとOne$Db
DaffodilDbとOne$Db
@features_1269_p
@features_1270_p
このデータベースの開発は止まっているようです。最後のリリースは2006年2月でした。
このデータベースの開発は止まっているようです。最後のリリースは2006年2月でした。
@features_1270_h3
@features_1271_h3
McKoi
McKoi
@features_1271_p
@features_1272_p
このデータベースの開発は止まっているようです。最後のリリースは2004年8月でした。
このデータベースの開発は止まっているようです。最後のリリースは2004年8月でした。
@features_1272_h2
@features_1273_h2
#H2 in Use
#H2 in Use
@features_1273_p
@features_1274_p
#For a list of applications that work with or use H2, see: <a href="links.html">Links</a> .
#For a list of applications that work with or use H2, see: <a href="links.html">Links</a> .
@features_1274_h2
@features_1275_h2
接続モード
接続モード
@features_1275_p
@features_1276_p
以下の接続モードがサポートされています:
以下の接続モードがサポートされています:
@features_1276_li
#Embedded mode (local connections using JDBC)
@features_1277_li
@features_1277_li
#Remote mode (remote connections using JDBC or ODBC over TCP/IP)
#Embedded mode (local connections using JDBC)
@features_1278_li
@features_1278_li
#Server mode (remote connections using JDBC or ODBC over TCP/IP)
@features_1279_li
#Mixed mode (local and remote connections at the same time)
#Mixed mode (local and remote connections at the same time)
@features_1279_h3
@features_1280_h3
エンベッドモード
エンベッドモード
@features_1280_p
@features_1281_p
#In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
#In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1281_h3
@features_1282_h3
#Remote Mode
サーバーモード
@features_1282_p
@features_1283_p
#When using the remote mode (sometimes called server mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine (or on another computer). Many applications can connect to the same database at the same time. The remote mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
#When using the server mode (sometimes called remote mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine, or on another computer. Many applications can connect to the same database at the same time. The server mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
@features_1283_h3
@features_1284_h3
#Mixed Mode
#Mixed Mode
@features_1284_p
@features_1285_p
#The mixed mode is a combination of the embedded and the remote mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The embedded connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower. All clients that want to connect to the database (no matter if it's an embedded or remote connection) can do so using the exact same database URL.
#The mixed mode is a combination of the embedded and the server mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The local connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower.
@features_1285_h2
@features_1286_p
#The server can be started and stopped from within the application (using the server API), or automatically (automatic mixed mode). When using the <a href="#auto_mixed_mode">automatic mixed mode</a> , all clients that want to connect to the database (no matter if it's an local or remote connection) can do so using the exact same database URL.
@features_1287_h2
データベースURL概要
データベースURL概要
@features_1286_p
@features_1288_p
#This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
#This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
#The database URL for connecting to a local database is <code>jdbc:h2:[file:][<path>]<databaseName></code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in: jdbc:h2:~/test.
#The database URL for connecting to a local database is <code>jdbc:h2:[file:][<path>]<databaseName></code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in: jdbc:h2:~/test. #時々、複数の接続が同じメモリオンリーデータベースを必要とします。このケースでは、データベースのURLに名前が含まれていなければなりません。例: <code>jdbc:h2:mem:db1</code> この方法での同じデータベースのアクセスは、同じ仮想マシンとClassLoader環境内でのみ動作します。
#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.
#By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
#By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
@features_1355_h2
@features_1359_h2
#Database Files Encryption
#Database Files Encryption
@features_1356_p
@features_1360_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.
#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_1357_h3
@features_1361_h3
#Creating a New Database with File Encryption
#Creating a New Database with File Encryption
@features_1358_p
@features_1362_p
#By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
#By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
@features_1359_h3
@features_1363_h3
#Connecting to an Encrypted Database
#Connecting to an Encrypted Database
@features_1360_p
@features_1364_p
#The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database:
#The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database: #データベースが開かれるときはいつも、データベースが使用中であると他のプロセスに合図するためにロックファイルが作成されます。もしデータベースが閉じられるか、データベースを開いたプロセスが終了するなら、ロックファイルは削除されます。
@features_1361_h3
@features_1365_h3
#Encrypting or Decrypting a Database
#Encrypting or Decrypting a Database
@features_1362_p
@features_1366_p
#If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES:
#If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES:
通常、データベースへの最後の接続が閉じられた時、データベースが終了されます。一部状況では、例えば、可能ではない時に接続をつなげたままにしておくことは、アプリケーションを減速させます。SQLステートメントの SET DB_CLOSE_DELAY <seconds> でデータベースの自動終了を遅らせるか、または無効にすることができます。secondsには、最後の接続が閉じられた後データベースを接続したままの状態に保つため、秒数を指定します。例えば、次のステートメントはデータベースを10秒間開かれた状態に保ちます:
通常、データベースへの最後の接続が閉じられた時、データベースが終了されます。一部状況では、例えば、可能ではない時に接続をつなげたままにしておくことは、アプリケーションを減速させます。SQLステートメントの SET DB_CLOSE_DELAY <seconds> でデータベースの自動終了を遅らせるか、または無効にすることができます。secondsには、最後の接続が閉じられた後データベースを接続したままの状態に保つため、秒数を指定します。例えば、次のステートメントはデータベースを10秒間開かれた状態に保ちます:
#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 '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: #アプリケーションは、同じデータベースへの複数の接続を含め、複数のデータベースを同時に開くことができます。開くデータベースの数は、利用可能なメモリによってのみ制限されています。
通常、SELECTステートメントはリードロックを生成します。これはサブクエリーも含まれます。データを修正するステートメントはライトロックを使用します。SELECT ... FOR UPDATE ステートメントを使用して、データの修正がなくても排他的にテーブルをロックすることも可能です。COMMITとROLLBACKステートメントは全ての周知のロックを解除します。SAVEPOINTとROLLBACK TO SAVEPOINTコマンドはロックに影響を及ぼしません。ロックはオートコミットモードに変更した時、オートコミットの接続がtrueにセットされた時 (この状態がデフォルトです) にも解除され、ロックはそれぞれのステートメントの後に解除されます。これは、どのステートメントでどんな種類のロックが生成されるかの概観です:
通常、SELECTステートメントはリードロックを生成します。これはサブクエリーも含まれます。データを修正するステートメントはライトロックを使用します。SELECT ... FOR UPDATE ステートメントを使用して、データの修正がなくても排他的にテーブルをロックすることも可能です。COMMITとROLLBACKステートメントは全ての周知のロックを解除します。SAVEPOINTとROLLBACK TO SAVEPOINTコマンドはロックに影響を及ぼしません。ロックはオートコミットモードに変更した時、オートコミットの接続がtrueにセットされた時 (この状態がデフォルトです) にも解除され、ロックはそれぞれのステートメントの後に解除されます。これは、どのステートメントでどんな種類のロックが生成されるかの概観です:
@features_1399_th
@features_1403_th
ロックの種類
ロックの種類
@features_1400_th
@features_1404_th
SQLステートメント
SQLステートメント
@features_1401_td
@features_1405_td
Read
Read
@features_1402_td
@features_1406_td
SELECT * FROM TEST
SELECT * FROM TEST
@features_1403_td
@features_1407_td
CALL SELECT MAX(ID) FROM TEST
CALL SELECT MAX(ID) FROM TEST
@features_1404_td
@features_1408_td
SCRIPT
SCRIPT
@features_1405_td
@features_1409_td
Write
Write
@features_1406_td
@features_1410_td
SELECT * FROM TEST WHERE 1=0 FOR UPDATE
SELECT * FROM TEST WHERE 1=0 FOR UPDATE
@features_1407_td
@features_1411_td
Write
Write
@features_1408_td
@features_1412_td
INSERT INTO TEST VALUES(1, 'Hello')
INSERT INTO TEST VALUES(1, 'Hello')
@features_1409_td
@features_1413_td
INSERT INTO TEST SELECT * FROM TEST
INSERT INTO TEST SELECT * FROM TEST
@features_1410_td
@features_1414_td
UPDATE TEST SET NAME='Hi'
UPDATE TEST SET NAME='Hi'
@features_1411_td
@features_1415_td
DELETE FROM TEST
DELETE FROM TEST
@features_1412_td
@features_1416_td
Write
Write
@features_1413_td
@features_1417_td
ALTER TABLE TEST ...
ALTER TABLE TEST ...
@features_1414_td
@features_1418_td
CREATE INDEX ... ON TEST ...
CREATE INDEX ... ON TEST ...
@features_1415_td
@features_1419_td
DROP INDEX ...
DROP INDEX ...
@features_1416_p
@features_1420_p
SQLコマンド SET LOCK_TIMEOUT <milliseconds> を使用して、ロックタイムアウトの例外が投げられるまでの秒数を、それぞれの接続ごとに別々に設定することができます。SQLコマンド SET DEFAULT_LOCK_TIMEOUT <milliseconds> を使用して、初期のロックタイムアウト (新しい接続に使用されるタイムアウト) を設定することができます。デフォルトのロックタイムアウトは永続的です。
SQLコマンド SET LOCK_TIMEOUT <milliseconds> を使用して、ロックタイムアウトの例外が投げられるまでの秒数を、それぞれの接続ごとに別々に設定することができます。SQLコマンド SET DEFAULT_LOCK_TIMEOUT <milliseconds> を使用して、初期のロックタイムアウト (新しい接続に使用されるタイムアウト) を設定することができます。デフォルトのロックタイムアウトは永続的です。
#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:
#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_1477_p
@features_1481_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: jdbc:h2:~/test;IGNORECASE=TRUE).
#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: jdbc:h2:~/test;IGNORECASE=TRUE).
@features_1478_h3
@features_1482_h3
互換モード
互換モード
@features_1479_p
@features_1483_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 difference to the regular mode:
#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 difference to the regular mode:
@features_1480_h3
@features_1484_h3
#DB2 Compatibility Mode
#DB2 Compatibility Mode
@features_1481_p
@features_1485_p
#To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
#To use the IBM DB2 mode, use the database URL <code>jdbc:h2:~/test;MODE=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
@features_1482_li
@features_1486_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1483_li
@features_1487_li
#Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
#Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
@features_1484_h3
@features_1488_h3
#Derby Compatibility Mode
#Derby Compatibility Mode
@features_1485_p
@features_1489_p
#To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
#To use the Apache Derby mode, use the database URL <code>jdbc:h2:~/test;MODE=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
@features_1486_li
@features_1490_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1487_li
@features_1491_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1488_h3
@features_1492_h3
#HSQLDB Compatibility Mode
#HSQLDB Compatibility Mode
@features_1489_p
@features_1493_p
#To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
#To use the HSQLDB mode, use the database URL <code>jdbc:h2:~/test;MODE=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
@features_1490_li
@features_1494_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1491_li
@features_1495_li
#When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
#When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
@features_1492_li
@features_1496_li
#Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
#Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
@features_1493_li
@features_1497_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1494_h3
@features_1498_h3
#MS SQL Server Compatibility Mode
#MS SQL Server Compatibility Mode
@features_1495_p
@features_1499_p
#To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
#To use the MS SQL Server mode, use the database URL <code>jdbc:h2:~/test;MODE=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
@features_1496_li
@features_1500_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1497_li
@features_1501_li
#Identifiers may be quoted using square brackets as in [Test].
#Identifiers may be quoted using square brackets as in [Test].
@features_1498_li
@features_1502_li
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
#For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
@features_1499_h3
@features_1503_h3
#MySQL Compatibility Mode
#MySQL Compatibility Mode
@features_1500_p
@features_1504_p
#To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
#To use the MySQL mode, use the database URL <code>jdbc:h2:~/test;MODE=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
@features_1501_li
@features_1505_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.
#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_1502_li
@features_1506_li
#Creating indexes in the CREATE TABLE statement should be supported.
#Creating indexes in the CREATE TABLE statement should be supported.
@features_1503_li
@features_1507_li
#The identifiers should be returned in lower case.
#The identifiers should be returned in lower case.
@features_1504_li
@features_1508_li
#When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
#When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
@features_1505_h3
@features_1509_h3
#Oracle Compatibility Mode
#Oracle Compatibility Mode
@features_1506_p
@features_1510_p
#To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
#To use the Oracle mode, use the database URL <code>jdbc:h2:~/test;MODE=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
@features_1507_li
@features_1511_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1508_li
@features_1512_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.
#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_1509_h3
@features_1513_h3
#PostgreSQL Compatibility Mode
#PostgreSQL Compatibility Mode
@features_1510_p
@features_1514_p
#To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
#To use the PostgreSQL mode, use the database URL <code>jdbc:h2:~/test;MODE=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
@features_1511_li
@features_1515_li
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
#For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
@features_1512_li
@features_1516_li
#Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
#Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
@features_1513_li
@features_1517_li
#When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
#When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
@features_1514_li
@features_1518_li
#The system columns 'CTID' and 'OID' should be supported.
#The system columns 'CTID' and 'OID' should be supported.
@features_1515_h2
@features_1519_h2
#Auto-Reconnect
#Auto-Reconnect
@features_1516_p
@features_1520_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.
#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_1517_p
@features_1521_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.
#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_1518_h2
@features_1522_h2
#Automatic Mixed Mode
#Automatic Mixed Mode
@features_1519_p
@features_1523_p
#Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
#Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
@features_1520_p
@features_1524_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.
#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_1521_p
@features_1525_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).
#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_1522_p
@features_1526_p
#This mode has three disadvantages: All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.
#This mode has three disadvantages: All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.
@features_1523_p
@features_1527_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).
#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).
#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.
#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_1543_a
@features_1547_a
#SLF4J
#SLF4J
@features_1544_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), JDK 1.4 logging, x4juli, and Simple Log.
#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), JDK 1.4 logging, x4juli, and Simple Log. #データベースファイルが読み取り専用なら、同様にデータベースも読み取り専用です。このデータベースで新しいテーブルを作成したり、データを追加したり変更したりすることはできません。SELECTステートメントのみ許可されています。読み取り専用データベースを作成するには、データベースを終了してログファイルを小さくします。ログファイルを削除してはいけません。そして、オペレーティングシステムを使用してデータベースファイルを読み取り専用にします。これでデータベースを開くと、読み取り専用になっています。アプリケーションが、データベースが読み取り専用であることを判断する方法は二つあります: Connection.isReadOnly() を呼ぶか、SQLステートメント CALL READONLY() を実行します。
@features_1545_p
@features_1549_p
#To enable SLF4J, set the file trace level to 4 in the database URL:
#To enable SLF4J, set the file trace level to 4 in the database URL:
@features_1546_p
@features_1550_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 in the file <database>.trace.db for error messages.
#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 in the file <database>.trace.db for error messages.
#Read Only Databases in Zip or Jar File #ディスクスペースが少ない状況での正しい取り扱い
@features_1550_p
@features_1554_p
#To create a read-only database in a zip, 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:
#To create a read-only database in a zip, 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_1551_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:
#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_1552_p
@features_1556_p
#Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database.
#Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database. #boot info (始動時に実行されるSQLスクリプト) が破損しているため、データベースを開くことができない場合、データベースイベントリスナーを指定することでデータベースを開くことができます。例外は記録されますが、データベースの開始は続行します。
@features_1553_h2
@features_1557_h2
ディスクスペースが少ない状況での正しい取り扱い
ディスクスペースが少ない状況での正しい取り扱い
@features_1554_p
@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 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.
#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. #インデックスの機能は、このデータベースによって直接サポートはされていませんが、computed columnsを使用することによって、簡単にエミュレートすることができます。例えば、カラムのupper-caseバージョンのインデックスが必要なら、原形のカラムのupper-caseバージョンのcomputed columnを作成し、このカラムにインデックスをつけます:
@features_1555_h3
@features_1559_h3
破損したデータベースを開く
破損したデータベースを開く
@features_1556_p
@features_1560_p
boot info (始動時に実行されるSQLスクリプト) が破損しているため、データベースを開くことができない場合、データベースイベントリスナーを指定することでデータベースを開くことができます。例外は記録されますが、データベースの開始は続行します。
boot info (始動時に実行されるSQLスクリプト) が破損しているため、データベースを開くことができない場合、データベースイベントリスナーを指定することでデータベースを開くことができます。例外は記録されますが、データベースの開始は続行します。
#Instead of passing the user name as a separate parameter as in <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself: <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter.
#Instead of passing the user name as a separate parameter as in <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself: <code>Connection conn = DriverManager. getConnection("jdbc:h2:~/test;USER=sa;PASSWORD=123");</code> The settings in the URL override the settings passed as a separate parameter. #完全なサンプルアプリケーションは src/test/org/h2/samples/Function.java をご覧下さい。
@features_1575_h2
@features_1579_h2
ユーザー定義の関数とストアドプロシージャ
ユーザー定義の関数とストアドプロシージャ
@features_1576_p
@features_1580_p
組み込み関数に加えて、このデータベースはユーザー定義のJava関数をサポートしています。同様に、このデータベースではJava関数はストアドプロシージャとして使用されています。関数は、使用される前に宣言 (登録) されていなければなりません。static Javaメソッドのみサポートされています; クラスとメソッドの両方が public である必要があります。Javaメソッドの例:
組み込み関数に加えて、このデータベースはユーザー定義のJava関数をサポートしています。同様に、このデータベースではJava関数はストアドプロシージャとして使用されています。関数は、使用される前に宣言 (登録) されていなければなりません。static Javaメソッドのみサポートされています; クラスとメソッドの両方が public である必要があります。Javaメソッドの例:
features_1264_p=*7 Derby only supports updatable result sets if the query is not sorted.
features_1264_p=*7 Derby only supports updatable result sets if the query is not sorted.
features_1265_p=*8 Derby and HSQLDB don't support standard compliant information schema tables. *9 H2 supports row level locks when using multi version concurrency.
features_1265_p=*8 Derby and HSQLDB don't support standard compliant information schema tables.
features_1266_h3=Derby and HSQLDB
features_1266_p=*9 H2 supports row level locks when using multi version concurrency.
features_1267_p=After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
features_1267_h3=Derby and HSQLDB
features_1268_h3=DaffodilDb and One$Db
features_1268_p=After an unexpected process termination (for example power failure), H2 can recover safely and automatically without any user interaction. For Derby and HSQLDB, some manual steps are required ('Another instance of Derby may have already booted the database' / 'The database is already in use by another process').
features_1269_p=It looks like the development of this database has stopped. The last release was February 2006.
features_1269_h3=DaffodilDb and One$Db
features_1270_h3=McKoi
features_1270_p=It looks like the development of this database has stopped. The last release was February 2006.
features_1271_p=It looks like the development of this database has stopped. The last release was August 2004
features_1271_h3=McKoi
features_1272_h2=H2 in Use
features_1272_p=It looks like the development of this database has stopped. The last release was August 2004
features_1273_p=For a list of applications that work with or use H2, see\:<a href\="links.html">Links</a> .
features_1273_h2=H2 in Use
features_1274_h2=Connection Modes
features_1274_p=For a list of applications that work with or use H2, see\:<a href\="links.html">Links</a> .
features_1275_p=The following connection modes are supported\:
features_1275_h2=Connection Modes
features_1276_li=Embedded mode (local connections using JDBC)
features_1276_p=The following connection modes are supported\:
features_1277_li=Remote mode (remote connections using JDBC or ODBC over TCP/IP)
features_1277_li=Embedded mode (local connections using JDBC)
features_1278_li=Mixed mode (local and remote connections at the same time)
features_1278_li=Server mode (remote connections using JDBC or ODBC over TCP/IP)
features_1279_h3=Embedded Mode
features_1279_li=Mixed mode (local and remote connections at the same time)
features_1280_p=In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
features_1280_h3=Embedded Mode
features_1281_h3=Remote Mode
features_1281_p=In embedded mode, an application opens a database from within the same JVM using JDBC. This is the fastest and easiest connection mode. The disadvantage is that a database may only be open in one virtual machine (and class loader) at any time. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
features_1282_p=When using the remote mode (sometimes called server mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine (or on another computer). Many applications can connect to the same database at the same time. The remote mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
features_1282_h3=Server Mode
features_1283_h3=Mixed Mode
features_1283_p=When using the server mode (sometimes called remote mode or client/server mode), an application opens a database remotely using the JDBC or ODBC API. A server needs to be started within the same or another virtual machine, or on another computer. Many applications can connect to the same database at the same time. The server mode is slower than the embedded mode, because all data is transferred over TCP/IP. As in all modes, both persistent and in-memory databases are supported. There is no limit on the number of database open concurrently, or on the number of open connections.
features_1284_p=The mixed mode is a combination of the embedded and the remote mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The embedded connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower. All clients that want to connect to the database (no matter if it's an embedded or remote connection) can do so using the exact same database URL.
features_1284_h3=Mixed Mode
features_1285_h2=Database URL Overview
features_1285_p=The mixed mode is a combination of the embedded and the server mode. The first application that connects to a database does that in embedded mode, but also starts a server so that other applications (running in different processes or virtual machines) can concurrently access the same data. The local connections are as fast as if the database is used in just the embedded mode, while the remote connections are a bit slower.
features_1286_p=This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
features_1286_p=The server can be started and stopped from within the application (using the server API), or automatically (automatic mixed mode). When using the <a href\="\#auto_mixed_mode">automatic mixed mode</a> , all clients that want to connect to the database (no matter if it's an local or remote connection) can do so using the exact same database URL.
features_1287_th=Topic
features_1287_h2=Database URL Overview
features_1288_th=URL Format and Examples
features_1288_p=This database supports multiple connection modes and connection settings. This is achieved using different database URLs. Settings in the URLs are not case sensitive.
features_1348_p=The database URL for connecting to a local database is <code>jdbc\:h2\:[file\:][<path>]<databaseName></code> . The prefix <code>file\:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in\:jdbc\:h2\:~/test.
features_1350_p=For certain use cases (for example\:rapid prototyping, testing, high performance operations, read-only databases), it may not be required to persist (changes to) the data at all. This database supports the memory-only mode, where the data is not persisted.
features_1351_p=In some cases, only one connection to a memory-only database is required. This means the database to be opened is private. In this case, the database URL is <code>jdbc\:h2\:mem\:</code> Opening two connections within the same virtual machine means opening two different (private) databases.
features_1351_h2=Connecting to an Embedded (Local) Database
features_1352_p=Sometimes multiple connections to the same memory-only database are required. In this case, the database URL must include a name. Example\:<code>jdbc\:h2\:mem\:db1</code> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
features_1352_p=The database URL for connecting to a local database is <code>jdbc\:h2\:[file\:][<path>]<databaseName></code> . The prefix <code>file\:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in\:jdbc\:h2\:~/test.
features_1353_p=It is also possible to access a memory-only database remotely (or from multiple processes in the same machine) using TCP/IP or SSL/TLS. An example database URL is\:<code>jdbc\:h2\:tcp\://localhost/mem\:db1</code> (using private database remotely is also possible).
features_1353_h2=Memory-Only Databases
features_1354_p=By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY\=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc\:h2\:mem\:test;DB_CLOSE_DELAY\=-1
features_1354_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_1355_h2=Database Files Encryption
features_1355_p=In some cases, only one connection to a memory-only database is required. This means the database to be opened is private. In this case, the database URL is <code>jdbc\:h2\:mem\:</code> Opening two connections within the same virtual machine means opening two different (private) databases.
features_1356_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_1356_p=Sometimes multiple connections to the same memory-only database are required. In this case, the database URL must include a name. Example\:<code>jdbc\:h2\:mem\:db1</code> . Accessing the same database in this way only works within the same virtual machine and class loader environment.
features_1357_h3=Creating a New Database with File Encryption
features_1357_p=It is also possible to access a memory-only database remotely (or from multiple processes in the same machine) using TCP/IP or SSL/TLS. An example database URL is\:<code>jdbc\:h2\:tcp\://localhost/mem\:db1</code> (using private database remotely is also possible).
features_1358_p=By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
features_1358_p=By default, when the last connection to a in-memory database is closed, the contents are lost. This can be disabled by adding ;DB_CLOSE_DELAY\=-1 to the database URL. That means to keep the contents of an in-memory database as long as the virtual machine is alive, use jdbc\:h2\:mem\:test;DB_CLOSE_DELAY\=-1
features_1359_h3=Connecting to an Encrypted Database
features_1359_h2=Database Files Encryption
features_1360_p=The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database\:
features_1360_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_1361_h3=Encrypting or Decrypting a Database
features_1361_h3=Creating a New Database with File Encryption
features_1362_p=If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES\:
features_1362_p=By default, a new database is automatically created if it does not exist yet. To create an encrypted database, connect to it as it would already exist.
features_1363_h2=Database File Locking
features_1363_h3=Connecting to an Encrypted Database
features_1364_p=Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
features_1364_p=The encryption algorithm is set in the database URL, and the file password is specified in the password field, before the user password. A single space needs to be added between the file password and the user password; the file password itself may not contain spaces. File passwords (as well as user passwords) are case sensitive. Here is an example to connect to a password-encrypted database\:
features_1365_p=The following file locking methods are implemented\:
features_1365_h3=Encrypting or Decrypting a Database
features_1366_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_1366_p=If you want to encrypt an existing database, use the ChangeFileEncryption tool. This tool can also decrypt an encrypted database, or change the file encryption key. It is available from within the H2 Console in the Tools section, or you can run it from the command line. The following command line will encrypt the database 'test' in the user home directory with the file password 'filepwd' and the encryption algorithm AES\:
features_1367_li=The second method is 'socket' and opens a server socket. The socket method does not require reading the lock file every second. The socket method should only be used if the database files are only accessed by the one (and always the same) computer.
features_1367_h2=Database File Locking
features_1368_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_1368_p=Whenever a database is opened, a lock file is created to signal other processes that the database is in use. If database is closed, or if the process that opened the database terminates, this lock file is deleted.
features_1369_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_1369_p=The following file locking methods are implemented\:
features_1370_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_1370_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_1371_p=For more information about the algorithms please see in Advanced Topics under File Locking Protocol.
features_1371_li=The second method is 'socket' and opens a server socket. The socket method does not require reading the lock file every second. The socket method should only be used if the database files are only accessed by the one (and always the same) computer.
features_1372_h2=Opening a Database Only if it Already Exists
features_1372_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_1373_p=By default, when an application calls <code>DriverManager.getConnection(url,...)</code> and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new database, and only open the database if it already exists. This can be done by adding <code>;ifexists\=true</code> to the URL. In this case, if the database does not already exist, an exception is thrown when trying to connect. The connection only succeeds when the database already exists. The complete URL may look like this\:
features_1373_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_1374_h2=Closing the Database
features_1374_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_1375_h3=Delayed Database Closing
features_1375_p=For more information about the algorithms please see in Advanced Topics under File Locking Protocol.
features_1376_p=Usually, the database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible leave the connection open. The automatic closing of the database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY <seconds>. The seconds specifies the number of seconds to keep a database open after the last connection to it was closed. For example the following statement will keep the database open for 10 seconds\:
features_1376_h2=Opening a Database Only if it Already Exists
features_1377_p=The value -1 means the database is never closed automatically. The value 0 is the default and means the database is closed when the last connection is closed. This setting is persistent and can be set by an administrator only. It is possible to set the value in the database URL\:<code>jdbc\:h2\:~/test;DB_CLOSE_DELAY\=10</code> .
features_1377_p=By default, when an application calls <code>DriverManager.getConnection(url,...)</code> and the database specified in the URL does not yet exist, a new (empty) database is created. In some situations, it is better to restrict creating new database, and only open the database if it already exists. This can be done by adding <code>;ifexists\=true</code> to the URL. In this case, if the database does not already exist, an exception is thrown when trying to connect. The connection only succeeds when the database already exists. The complete URL may look like this\:
features_1378_h3=Don't Close the Database when the VM Exits
features_1378_h2=Closing the Database
features_1379_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. This is done using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). 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_1379_h3=Delayed Database Closing
features_1380_h2=Log Index Changes
features_1380_p=Usually, the database is closed when the last connection to it is closed. In some situations this slows down the application, for example when it is not possible leave the connection open. The automatic closing of the database can be delayed or disabled with the SQL statement SET DB_CLOSE_DELAY <seconds>. The seconds specifies the number of seconds to keep a database open after the last connection to it was closed. For example the following statement will keep the database open for 10 seconds\:
features_1381_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 jdbc\:h2\:~/test;LOG\=2 This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
features_1381_p=The value -1 means the database is never closed automatically. The value 0 is the default and means the database is closed when the last connection is closed. This setting is persistent and can be set by an administrator only. It is possible to set the value in the database URL\:<code>jdbc\:h2\:~/test;DB_CLOSE_DELAY\=10</code> .
features_1382_h2=Ignore Unknown Settings
features_1382_h3=Don't Close the Database when the VM Exits
features_1383_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_1383_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. This is done using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). 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_1384_h2=Changing Other Settings when Opening a Connection
features_1384_h2=Log Index Changes
features_1385_p=In addition to the settings already described (cipher, file_lock, ifexists, user, password), other database settings can be passed in the database URL. Adding <code>setting\=value</code> at the end of an URL is the same as executing the statement <code>SET setting value</code> just after connecting. For a list of settings supported by this database please see the SQL grammar documentation.
features_1385_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 jdbc\:h2\:~/test;LOG\=2 This setting should be specified when connecting. The update performance of the database will be reduced when using this option.
features_1386_h2=Custom File Access Mode
features_1386_h2=Ignore Unknown Settings
features_1387_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_1387_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_1388_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_1388_h2=Changing Other Settings when Opening a Connection
features_1389_h2=Multiple Connections
features_1389_p=In addition to the settings already described (cipher, file_lock, ifexists, user, password), other database settings can be passed in the database URL. Adding <code>setting\=value</code> at the end of an URL is the same as executing the statement <code>SET setting value</code> just after connecting. For a list of settings supported by this database please see the SQL grammar documentation.
features_1390_h3=Opening Multiple Databases at the Same Time
features_1390_h2=Custom File Access Mode
features_1391_p=An application can open multiple databases at the same time, including multiple connections to the same database. The number of open database is only limited by the memory available.
features_1391_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_1392_h3=Multiple Connections to the Same Database\:Client/Server
features_1392_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_1393_p=If you want to access the same database at the same time from different processes or computers, you need to use the client / server mode. In this case, one process acts as the server, and the other processes (that could reside on other computers as well) connect to the server via TCP/IP (or SSL/TLS over TCP/IP for improved security).
features_1393_h2=Multiple Connections
features_1394_h3=Multithreading Support
features_1394_h3=Opening Multiple Databases at the Same Time
features_1395_p=This database is multithreading-safe. That means, if an application is multi-threaded, it does not need o worry about synchronizing the access to the database. Internally, most requests to the same database are synchronized. That means an application can use multiple threads accessing the same database at the same time, however if one thread executes a long running query, the other threads need to wait.
features_1395_p=An application can open multiple databases at the same time, including multiple connections to the same database. The number of open database is only limited by the memory available.
features_1396_h3=Locking, Lock-Timeout, Deadlocks
features_1396_h3=Multiple Connections to the Same Database\:Client/Server
features_1397_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). If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
features_1397_p=If you want to access the same database at the same time from different processes or computers, you need to use the client / server mode. In this case, one process acts as the server, and the other processes (that could reside on other computers as well) connect to the server via TCP/IP (or SSL/TLS over TCP/IP for improved security).
features_1398_p=Usually, SELECT statement will generate read locks. This includes subqueries. Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data, using the statement SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. Here is an overview on what statements generate what type of lock\:
features_1398_h3=Multithreading Support
features_1399_th=Type of Lock
features_1399_p=This database is multithreading-safe. That means, if an application is multi-threaded, it does not need o worry about synchronizing the access to the database. Internally, most requests to the same database are synchronized. That means an application can use multiple threads accessing the same database at the same time, however if one thread executes a long running query, the other threads need to wait.
features_1400_th=SQL Statement
features_1400_h3=Locking, Lock-Timeout, Deadlocks
features_1401_td=Read
features_1401_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). If a connection wants to reads from a table, and there is no write lock on the table, then a read lock is added to the table. If there is a write lock, then this connection waits for the other connection to release the lock. If connection cannot get a lock for a specified time, then a lock timeout exception is thrown.
features_1402_td=SELECT * FROM TEST
features_1402_p=Usually, SELECT statement will generate read locks. This includes subqueries. Statements that modify data use write locks. It is also possible to lock a table exclusively without modifying data, using the statement SELECT ... FOR UPDATE. The statements COMMIT and ROLLBACK releases all open locks. The commands SAVEPOINT and ROLLBACK TO SAVEPOINT don't affect locks. The locks are also released when the autocommit mode changes, and for connections with autocommit set to true (this is the default), locks are released after each statement. Here is an overview on what statements generate what type of lock\:
features_1403_td=CALL SELECT MAX(ID) FROM TEST
features_1403_th=Type of Lock
features_1404_td=SCRIPT
features_1404_th=SQL Statement
features_1405_td=Write
features_1405_td=Read
features_1406_td=SELECT * FROM TEST WHERE 1\=0 FOR UPDATE
features_1406_td=SELECT * FROM TEST
features_1407_td=Write
features_1407_td=CALL SELECT MAX(ID) FROM TEST
features_1408_td=INSERT INTO TEST VALUES(1, 'Hello')
features_1408_td=SCRIPT
features_1409_td=INSERT INTO TEST SELECT * FROM TEST
features_1409_td=Write
features_1410_td=UPDATE TEST SET NAME\='Hi'
features_1410_td=SELECT * FROM TEST WHERE 1\=0 FOR UPDATE
features_1411_td=DELETE FROM TEST
features_1411_td=Write
features_1412_td=Write
features_1412_td=INSERT INTO TEST VALUES(1, 'Hello')
features_1413_td=ALTER TABLE TEST ...
features_1413_td=INSERT INTO TEST SELECT * FROM TEST
features_1414_td=CREATE INDEX ... ON TEST ...
features_1414_td=UPDATE TEST SET NAME\='Hi'
features_1415_td=DROP INDEX ...
features_1415_td=DELETE FROM TEST
features_1416_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 <milliseconds>. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT <milliseconds>. The default lock timeout is persistent.
features_1416_td=Write
features_1417_h2=Database File Layout
features_1417_td=ALTER TABLE TEST ...
features_1418_p=There are a number of files created for persistent databases. Other than some databases, not every table and/or index is stored in its own file. Instead, usually only the following files are created\:A data file, an index file, a log file, and a database lock file (exists only while the database is in use). In addition to that, a file is created for each large object (CLOB/BLOB), a file for each linear index, and temporary files for large result sets. Then the command SCRIPT can create script files. If the database trace option is enabled, trace files are created. The following files can be created by the database\:
features_1418_td=CREATE INDEX ... ON TEST ...
features_1419_th=File Name
features_1419_td=DROP INDEX ...
features_1420_th=Description
features_1420_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 <milliseconds>. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT <milliseconds>. The default lock timeout is persistent.
features_1421_th=Number of Files
features_1421_h2=Database File Layout
features_1422_td=test.data.db
features_1422_p=There are a number of files created for persistent databases. Other than some databases, not every table and/or index is stored in its own file. Instead, usually only the following files are created\:A data file, an index file, a log file, and a database lock file (exists only while the database is in use). In addition to that, a file is created for each large object (CLOB/BLOB), a file for each linear index, and temporary files for large result sets. Then the command SCRIPT can create script files. If the database trace option is enabled, trace files are created. The following files can be created by the database\:
features_1423_td=Data file
features_1423_th=File Name
features_1424_td=Contains the data for all tables
features_1424_th=Description
features_1425_td=Format\:<database>.data.db
features_1425_th=Number of Files
features_1426_td=1 per database
features_1426_td=test.data.db
features_1427_td=test.index.db
features_1427_td=Data file
features_1428_td=Index file
features_1428_td=Contains the data for all tables
features_1429_td=Contains the data for all (btree) indexes
features_1463_h3=Moving and Renaming Database Files
features_1463_td=Hash index file
features_1464_p=Database name and location are not stored inside the database names.
features_1464_td=Contains the data for a linear hash index
features_1465_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_1466_p=As there is no platform specific data in the files, they can be moved to other operating systems without problems.
features_1466_td=1 per linear hash index
features_1467_h3=Backup
features_1467_h3=Moving and Renaming Database Files
features_1468_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_1468_p=Database name and location are not stored inside the database names.
features_1469_p=To backup data while the database is running, the SQL command SCRIPT can be used.
features_1469_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_1470_h2=Logging and Recovery
features_1470_p=As there is no platform specific data in the files, they can be moved to other operating systems without problems.
features_1471_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_1471_h3=Backup
features_1472_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_1472_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_1473_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_1473_p=To backup data while the database is running, the SQL command SCRIPT can be used.
features_1474_p=If the database file is corrupted, because the checksum of a record does not match (for example, if the file was edited with another application), the database can be opened in recovery mode. In this case, errors in the database are logged but not thrown. The database should be backed up to a script and re-built as soon as possible. To open the database in the recovery mode, use a database URL must contain RECOVER\=1, as in jdbc\:h2\:~/test;RECOVER\=1. Indexes are rebuilt in this case, and the summary (object allocation table) is not read in this case, so opening the database takes longer.
features_1474_h2=Logging and Recovery
features_1475_h2=Compatibility
features_1475_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_1476_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_1476_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_1477_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\:jdbc\:h2\:~/test;IGNORECASE\=TRUE).
features_1477_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_1478_h3=Compatibility Modes
features_1478_p=If the database file is corrupted, because the checksum of a record does not match (for example, if the file was edited with another application), the database can be opened in recovery mode. In this case, errors in the database are logged but not thrown. The database should be backed up to a script and re-built as soon as possible. To open the database in the recovery mode, use a database URL must contain RECOVER\=1, as in jdbc\:h2\:~/test;RECOVER\=1. Indexes are rebuilt in this case, and the summary (object allocation table) is not read in this case, so opening the database takes longer.
features_1479_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 difference to the regular mode\:
features_1479_h2=Compatibility
features_1480_h3=DB2 Compatibility Mode
features_1480_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_1481_p=To use the IBM DB2 mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
features_1481_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\:jdbc\:h2\:~/test;IGNORECASE\=TRUE).
features_1482_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1482_h3=Compatibility Modes
features_1483_li=Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
features_1483_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 difference to the regular mode\:
features_1484_h3=Derby Compatibility Mode
features_1484_h3=DB2 Compatibility Mode
features_1485_p=To use the Apache Derby mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
features_1485_p=To use the IBM DB2 mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=DB2</code> or the SQL statement <code>SET MODE DB2</code> .
features_1486_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1486_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1487_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1487_li=Support for the syntax [OFFSET .. ROW] [FETCH ... ONLY] as an alternative syntax for LIMIT .. OFFSET.
features_1488_h3=HSQLDB Compatibility Mode
features_1488_h3=Derby Compatibility Mode
features_1489_p=To use the HSQLDB mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
features_1489_p=To use the Apache Derby mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=Derby</code> or the SQL statement <code>SET MODE Derby</code> .
features_1490_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1490_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1491_li=When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
features_1491_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1492_li=Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
features_1492_h3=HSQLDB Compatibility Mode
features_1493_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1493_p=To use the HSQLDB mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=HSQLDB</code> or the SQL statement <code>SET MODE HSQLDB</code> .
features_1494_h3=MS SQL Server Compatibility Mode
features_1494_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1495_p=To use the MS SQL Server mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
features_1495_li=When converting the scale of decimal data, the number is only converted if the new scale is smaller then current scale. Usually, the scale is converted and 0s are added if required.
features_1496_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1496_li=Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
features_1497_li=Identifiers may be quoted using square brackets as in [Test].
features_1497_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1498_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1498_h3=MS SQL Server Compatibility Mode
features_1499_h3=MySQL Compatibility Mode
features_1499_p=To use the MS SQL Server mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=MSSQLServer</code> or the SQL statement <code>SET MODE MSSQLServer</code> .
features_1500_p=To use the MySQL mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
features_1500_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1501_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_1501_li=Identifiers may be quoted using square brackets as in [Test].
features_1502_li=Creating indexes in the CREATE TABLE statement should be supported.
features_1502_li=For unique indexes, NULL is distinct. That means only one row with NULL in one of the columns is allowed.
features_1503_li=The identifiers should be returned in lower case.
features_1503_h3=MySQL Compatibility Mode
features_1504_li=When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
features_1504_p=To use the MySQL mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=MySQL</code> or the SQL statement <code>SET MODE MySQL</code> .
features_1505_h3=Oracle Compatibility Mode
features_1505_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_1506_p=To use the Oracle mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
features_1506_li=Creating indexes in the CREATE TABLE statement should be supported.
features_1507_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1507_li=The identifiers should be returned in lower case.
features_1508_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_1508_li=When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
features_1509_h3=PostgreSQL Compatibility Mode
features_1509_h3=Oracle Compatibility Mode
features_1510_p=To use the PostgreSQL mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
features_1510_p=To use the Oracle mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=Oracle</code> or the SQL statement <code>SET MODE Oracle</code> .
features_1511_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1511_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1512_li=Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
features_1512_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 converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
features_1513_h3=PostgreSQL Compatibility Mode
features_1514_li=The system columns 'CTID' and 'OID' should be supported.
features_1514_p=To use the PostgreSQL mode, use the database URL <code>jdbc\:h2\:~/test;MODE\=PostgreSQL</code> or the SQL statement <code>SET MODE PostgreSQL</code> .
features_1515_h2=Auto-Reconnect
features_1515_li=For aliased columns, ResultSetMetaData.getColumnName() returns the alias name and getTableName() returns null.
features_1516_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_1516_li=Concatenation of a NULL with another value results in NULL. Usually, the NULL is treated as an empty string if only one of the operators is NULL, and NULL is only returned if both values are NULL.
features_1517_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_1517_li=When converting a floating point number to a integer, the fractional digits should not be truncated, but the value should be rounded.
features_1518_h2=Automatic Mixed Mode
features_1518_li=The system columns 'CTID' and 'OID' should be supported.
features_1519_p=Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER\=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
features_1519_h2=Auto-Reconnect
features_1520_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_1520_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_1521_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_1521_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=This mode has three disadvantages\:All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc\:h2\:tcp\:// or ssl\://) are not supported.
features_1522_h2=Automatic Mixed Mode
features_1523_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_1523_p=Multiple processes can access the same database without having to start the server manually. To do that, append <code>;AUTO_SERVER\=TRUE</code> to the database URL. You can use the same database URL no matter if the database is already open or not.
features_1524_h2=Using the Trace Options
features_1524_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_1525_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_1525_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_li=Trace to System.out and/or a file
features_1526_p=This mode has three disadvantages\:All processes need to have access to the database files. Then, if the first connection is closed (the connection that started the server), open transactions of other connections will be rolled back. Also, explicit client/server connections (using jdbc\:h2\:tcp\:// or ssl\://) are not supported.
features_1527_li=Support for trace levels OFF, ERROR, INFO, and DEBUG
features_1527_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_1528_li=The maximum size of the trace file can be set
features_1528_h2=Using the Trace Options
features_1529_li=The Java code generation is possible
features_1529_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_1530_li=Trace can be enabled at runtime by manually creating a file
features_1530_li=Trace to System.out and/or a file
features_1531_h3=Trace Options
features_1531_li=Support for trace levels OFF, ERROR, INFO, and DEBUG
features_1532_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_1532_li=The maximum size of the trace file can be set
features_1533_p=The trace level can be changed at runtime by executing the SQL command <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for System.out tracing) or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing). Example\:
features_1533_li=The Java code generation is possible
features_1534_h3=Setting the Maximum Size of the Trace File
features_1534_li=Trace can be enabled at runtime by manually creating a file
features_1535_p=When using a high trace level, the trace file can get very big quickly. The size of the file can be limited by executing the SQL statement <code>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . If the log file exceeds the limit, the file is renamed to .old and a new file is created. If another .old file exists, it is deleted. The default setting is 16 MB. Example\:
features_1535_h3=Trace Options
features_1536_h3=Java Code Generation
features_1536_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=When setting the trace level to INFO or DEBUG, Java source code is generated as well, so that problem can be reproduced more easily. The trace file looks like this\:
features_1537_p=The trace level can be changed at runtime by executing the SQL command <code>SET TRACE_LEVEL_SYSTEM_OUT level</code> (for System.out tracing) or <code>SET TRACE_LEVEL_FILE level</code> (for file tracing). Example\:
features_1538_p=You need to filter out the lines without /**/ to get the Java source code. In Windows, a simple way to do that is\:
features_1538_h3=Setting the Maximum Size of the Trace File
features_1539_p=Afterwards, you need to complete the file Trace.java before it can be compiled, for example with\:
features_1539_p=When using a high trace level, the trace file can get very big quickly. The size of the file can be limited by executing the SQL statement <code>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</code> . If the log file exceeds the limit, the file is renamed to .old and a new file is created. If another .old file exists, it is deleted. The default setting is 16 MB. Example\:
features_1540_p=Also, the user name and password needs to be set, because they are not listed in the trace file.
features_1540_h3=Java Code Generation
features_1541_h2=Using Other Logging APIs
features_1541_p=When setting the trace level to INFO or DEBUG, Java source code is generated as well, so that problem can be reproduced more easily. The trace file looks like this\:
features_1542_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_1542_p=You need to filter out the lines without /**/ to get the Java source code. In Windows, a simple way to do that is\:
features_1543_a=SLF4J
features_1543_p=Afterwards, you need to complete the file Trace.java before it can be compiled, for example with\:
features_1544_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), JDK 1.4 logging, x4juli, and Simple Log.
features_1544_p=Also, the user name and password needs to be set, because they are not listed in the trace file.
features_1545_p=To enable SLF4J, set the file trace level to 4 in the database URL\:
features_1545_h2=Using Other Logging APIs
features_1546_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 in the file <database>.trace.db for error messages.
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 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_1547_h2=Read Only Databases
features_1547_a=SLF4J
features_1548_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 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 a database is read-only\:By calling Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
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), JDK 1.4 logging, x4juli, and Simple Log.
features_1549_h2=Read Only Databases in Zip or Jar File
features_1549_p=To enable SLF4J, set the file trace level to 4 in the database URL\:
features_1550_p=To create a read-only database in a zip, 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_1550_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 in the file <database>.trace.db for error messages.
features_1551_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_1551_h2=Read Only Databases
features_1552_p=Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database.
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 SELECT 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 a database is read-only\:By calling Connection.isReadOnly() or by executing the SQL statement CALL READONLY().
features_1553_h2=Graceful Handling of Low Disk Space Situations
features_1553_h2=Read Only Databases in Zip or Jar File
features_1554_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_1554_p=To create a read-only database in a zip, 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_1555_h3=Opening a Corrupted Database
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=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_1556_p=Databases in a zip file 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; so large databases are supported as well. The same indexes are used than when using a regular database.
features_1557_h2=Computed Columns / Function Based Index
features_1557_h2=Graceful Handling of Low Disk Space Situations
features_1558_p=Function indexes are not directly supported by this database, but they can be easily emulated by using computed columns. For example, if an index on the upper-case version of a column is required, just create a computed column with the upper-case version of the original column, and index this column\:
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 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_1559_p=When inserting data, it is not required (better\:not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table\:
features_1559_h3=Opening a Corrupted Database
features_1560_h2=Multi-Dimensional Indexes
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_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_1561_h2=Computed Columns / Function Based Index
features_1562_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_1562_p=Function indexes are not directly supported by this database, but they can be easily emulated by using computed columns. For example, if an index on the upper-case version of a column is required, just create a computed column with the upper-case version of the original column, and index this column\:
features_1563_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_1563_p=When inserting data, it is not required (better\:not allowed) to specify a value for the upper-case version of the column, because the value is generated. But you can use the column when querying the table\:
features_1564_h2=Using Passwords
features_1564_h2=Multi-Dimensional Indexes
features_1565_h3=Using Secure Passwords
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=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_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=i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
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_h3=Passwords\:Using Char Arrays instead of Strings
features_1568_h2=Using Passwords
features_1569_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_1569_h3=Using Secure Passwords
features_1570_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_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=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_1571_p=i'sE2rtPiUKtT (it's easy to remember this password if you know the trick)
features_1572_p=In this example, the password is hard code in the application, which is not secure of course. However, Java Swing supports a way to get passwords using a char array (JPasswordField).
features_1572_h3=Passwords\:Using Char Arrays instead of Strings
features_1573_h3=Passing the User Name and/or Password in the URL
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=Instead of passing the user name as a separate parameter as in <code>Connection conn \=DriverManager. getConnection("jdbc\:h2\:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself\:<code>Connection conn \=DriverManager. getConnection("jdbc\:h2\:~/test;USER\=sa;PASSWORD\=123");</code> The settings in the URL override the settings passed as a separate parameter.
features_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_h2=User-Defined Functions and Stored Procedures
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=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_1576_p=In this example, the password is hard code in the application, which is not secure of course. However, Java Swing supports a way to get passwords using a char array (JPasswordField).
features_1577_p=The Java function must be registered in the database by calling CREATE ALIAS\:
features_1577_h3=Passing the User Name and/or Password in the URL
features_1578_p=For a complete sample application, see src/test/org/h2/samples/Function.java.
features_1578_p=Instead of passing the user name as a separate parameter as in <code>Connection conn \=DriverManager. getConnection("jdbc\:h2\:~/test", "sa", "123");</code> the user name (and/or password) can be supplied in the URL itself\:<code>Connection conn \=DriverManager. getConnection("jdbc\:h2\:~/test;USER\=sa;PASSWORD\=123");</code> The settings in the URL override the settings passed as a separate parameter.
features_1579_h3=Function Data Type Mapping
features_1579_h2=User-Defined Functions and Stored Procedures
features_1580_p=Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. In this case, the value NULL is used as the result. If the function should be called in this case, you need to use 'java.lang.Integer' instead of 'int'.
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_h3=Functions that require a Connection
features_1581_p=The Java function must be registered in the database by calling CREATE ALIAS\:
features_1582_p=If the first parameter in a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning.
features_1582_p=For a complete sample application, see src/test/org/h2/samples/Function.java.
features_1583_h3=Functions throwing an Exception
features_1583_h3=Function Data Type Mapping
features_1584_p=If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
features_1584_p=Functions that accept non-nullable parameters such as 'int' will not be called if one of those parameters is NULL. In this case, the value NULL is used as the result. If the function should be called in this case, you need to use 'java.lang.Integer' instead of 'int'.
features_1585_h3=Functions returning a Result Set
features_1585_h3=Functions that require a Connection
features_1586_p=Functions may returns a result set. Such a function can be called with the CALL statement\:
features_1586_p=If the first parameter in a Java function is a java.sql.Connection, then the connection to database is provided. This connection does not need to be closed before returning.
features_1587_h3=Using SimpleResultSet
features_1587_h3=Functions throwing an Exception
features_1588_p=A function that returns a result set can create this result set from scratch using the SimpleResultSet tool\:
features_1588_p=If a function throws an Exception, then the current statement is rolled back and the exception is thrown to the application.
features_1589_h3=Using a Function as a Table
features_1589_h3=Functions returning a Result Set
features_1590_p=A function returning a result set can be like a table. However, in this case the function is called at least twice\:First while parsing the statement to collect the column names (with parameters set to null where not known at compile time). And then, while executing the statement to get the data (may be repeatedly if this is a join). If the function is called just to get the column list, the URL of the connection passed to the function is jdbc\:columnlist\:connection. Otherwise, the URL of the connection is jdbc\:default\:connection.
features_1590_p=Functions may returns a result set. Such a function can be called with the CALL statement\:
features_1591_h2=Triggers
features_1591_h3=Using SimpleResultSet
features_1592_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\:
features_1592_p=A function that returns a result set can create this result set from scratch using the SimpleResultSet tool\:
features_1593_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_1593_h3=Using a Function as a Table
features_1594_p=The trigger can be used to veto a change, by throwing a SQL Exception.
features_1594_p=A function returning a result set can be like a table. However, in this case the function is called at least twice\:First while parsing the statement to collect the column names (with parameters set to null where not known at compile time). And then, while executing the statement to get the data (may be repeatedly if this is a join). If the function is called just to get the column list, the URL of the connection passed to the function is jdbc\:columnlist\:connection. Otherwise, the URL of the connection is jdbc\:default\:connection.
features_1595_h2=Compacting a Database
features_1595_h2=Triggers
features_1596_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_1596_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\:
features_1597_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_1597_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_1598_h2=Cache Settings
features_1598_p=The trigger can be used to veto a change, by throwing a SQL Exception.
features_1599_p=The database keeps most frequently used data and index pages in the main memory. The amount of memory used for caching can be changed using the setting CACHE_SIZE. This setting can be set in the database connection URL (jdbc\:h2\:~/test;CACHE_SIZE\=131072), or it can be changed at runtime using SET CACHE_SIZE size.
features_1599_h2=Compacting a Database
features_1600_p=This database supports two cache page replacement algorithms\:LRU (the default) and 2Q. For LRU, the pages that were least frequently used are removed from the cache if it becomes full. The 2Q algorithm is a bit more complicated\:basically two queues are used. The 2Q algorithm is more resistant to table scans, however the overhead is a bit higher compared to the LRU. To use the cache algorithm 2Q, use a database URL of the form jdbc\:h2\:~/test;CACHE_TYPE\=TQ. The cache algorithm cannot be changed once the database is open.
features_1600_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=To get information about page reads and writes, and the current caching algorithm in use, call SELECT * FROM INFORMATION_SCHEMA.SETTINGS. The number of pages read / written is listed for the data and index file.
features_1601_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_h2=Cache Settings
features_1603_p=The database keeps most frequently used data and index pages in the main memory. The amount of memory used for caching can be changed using the setting CACHE_SIZE. This setting can be set in the database connection URL (jdbc\:h2\:~/test;CACHE_SIZE\=131072), or it can be changed at runtime using SET CACHE_SIZE size.
features_1604_p=This database supports two cache page replacement algorithms\:LRU (the default) and 2Q. For LRU, the pages that were least frequently used are removed from the cache if it becomes full. The 2Q algorithm is a bit more complicated\:basically two queues are used. The 2Q algorithm is more resistant to table scans, however the overhead is a bit higher compared to the LRU. To use the cache algorithm 2Q, use a database URL of the form jdbc\:h2\:~/test;CACHE_TYPE\=TQ. The cache algorithm cannot be changed once the database is open.
features_1605_p=To get information about page reads and writes, and the current caching algorithm in use, call SELECT * FROM INFORMATION_SCHEMA.SETTINGS. The number of pages read / written is listed for the data and index file.