提交 0683dd5e authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 df90fb37
...@@ -448,7 +448,7 @@ concurrently access the same data. The local connections are as fast as if ...@@ -448,7 +448,7 @@ 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 the database is used in just the embedded mode, while the remote
connections are a bit slower. connections are a bit slower.
</p><p> </p><p>
The server can be started and stopped from within the application (using the server API), 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>, 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 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. it's an local or remote connection) can do so using the exact same database URL.
......
...@@ -2729,7 +2729,7 @@ Main Features ...@@ -2729,7 +2729,7 @@ Main Features
Very fast database engine Very fast database engine
@features_1038_li @features_1038_li
Free, with source code Open source
@features_1039_li @features_1039_li
Written in Java Written in Java
...@@ -2852,13 +2852,13 @@ EXPLAIN PLAN support, sophisticated trace options ...@@ -2852,13 +2852,13 @@ EXPLAIN PLAN support, sophisticated trace options
Database closing can be delayed or disabled to improve the performance Database closing can be delayed or disabled to improve the performance
@features_1079_li @features_1079_li
Web-based Console application (English, German, partially French and Spanish) with autocomplete Web-based Console application (translated to many languages) with autocomplete
@features_1080_li @features_1080_li
The database can generate SQL script files The database can generate SQL script files
@features_1081_li @features_1081_li
Contains a recovery tool that can dump the contents of the data file 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)
...@@ -3410,1014 +3410,1026 @@ Footprint (jar/dll size) ...@@ -3410,1014 +3410,1026 @@ Footprint (jar/dll size)
*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.
@features_1287_th @features_1289_th
Topic Topic
@features_1288_th @features_1290_th
URL Format and Examples URL Format and Examples
@features_1289_a @features_1291_a
Embedded (local) connection Embedded (local) connection
@features_1290_td @features_1292_td
jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt; jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;
@features_1291_td @features_1293_td
jdbc:h2:~/test jdbc:h2:~/test
@features_1292_td @features_1294_td
jdbc:h2:file:/data/sample jdbc:h2:file:/data/sample
@features_1293_td @features_1295_td
jdbc:h2:file:C:/data/sample (Windows only) jdbc:h2:file:C:/data/sample (Windows only)
@features_1294_a @features_1296_a
In-Memory (private) In-memory (private)
@features_1295_td @features_1297_td
jdbc:h2:mem: jdbc:h2:mem:
@features_1296_a @features_1298_a
In-Memory (named) In-memory (named)
@features_1297_td @features_1299_td
jdbc:h2:mem:&lt;databaseName&gt; jdbc:h2:mem:&lt;databaseName&gt;
@features_1298_td @features_1300_td
jdbc:h2:mem:test_mem jdbc:h2:mem:test_mem
@features_1299_a @features_1301_a
Remote using TCP/IP Server mode (remote connections)
@features_1300_td @features_1302_a
using TCP/IP
@features_1303_td
jdbc:h2:tcp://&lt;server&gt;[:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt; jdbc:h2:tcp://&lt;server&gt;[:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt;
@features_1301_td @features_1304_td
jdbc:h2:tcp://localhost/~/test jdbc:h2:tcp://localhost/~/test
@features_1302_td @features_1305_td
jdbc:h2:tcp://dbserv:8084/~/sample jdbc:h2:tcp://dbserv:8084/~/sample
@features_1303_a @features_1306_a
Remote using SSL/TLS Server mode (remote connections)
@features_1304_td @features_1307_a
using SSL/TLS
@features_1308_td
jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt; jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt;
@features_1305_td @features_1309_td
jdbc:h2:ssl://secureserv:8085/~/sample; jdbc:h2:ssl://secureserv:8085/~/sample;
@features_1306_a @features_1310_a
Using Encrypted Files Using encrypted files
@features_1307_td @features_1311_td
jdbc:h2:&lt;url&gt;;CIPHER=[AES|XTEA] jdbc:h2:&lt;url&gt;;CIPHER=[AES|XTEA]
@features_1308_td @features_1312_td
jdbc:h2:ssl://secureserv/~/testdb;CIPHER=AES jdbc:h2:ssl://secureserv/~/testdb;CIPHER=AES
@features_1309_td @features_1313_td
jdbc:h2:file:~/secure;CIPHER=XTEA jdbc:h2:file:~/secure;CIPHER=XTEA
@features_1310_a @features_1314_a
File Locking Methods File locking methods
@features_1311_td @features_1315_td
jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET} jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET}
@features_1312_td @features_1316_td
jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO
@features_1313_td @features_1317_td
jdbc:h2:file:~/private;CIPHER=XTEA;FILE_LOCK=SOCKET jdbc:h2:file:~/private;CIPHER=XTEA;FILE_LOCK=SOCKET
@features_1314_a @features_1318_a
Only Open if it Already Exists Only open if it already exists
@features_1315_td @features_1319_td
jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE
@features_1316_td @features_1320_td
jdbc:h2:file:~/sample;IFEXISTS=TRUE jdbc:h2:file:~/sample;IFEXISTS=TRUE
@features_1317_a @features_1321_a
Don't Close the Database when the VM Exits Don't close the database when the VM exits
@features_1318_td @features_1322_td
jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE
@features_1319_a @features_1323_a
User Name and/or Password User name and/or password
@features_1320_td @features_1324_td
jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;] jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;]
@features_1321_td @features_1325_td
jdbc:h2:file:~/sample;USER=sa;PASSWORD=123 jdbc:h2:file:~/sample;USER=sa;PASSWORD=123
@features_1322_a @features_1326_a
Log Index Changes Log index changes
@features_1323_td @features_1327_td
jdbc:h2:&lt;url&gt;;LOG=2 jdbc:h2:&lt;url&gt;;LOG=2
@features_1324_td @features_1328_td
jdbc:h2:file:~/sample;LOG=2 jdbc:h2:file:~/sample;LOG=2
@features_1325_a @features_1329_a
Debug Trace Settings Debug trace settings
@features_1326_td @features_1330_td
jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt; jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt;
@features_1327_td @features_1331_td
jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3 jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3
@features_1328_a @features_1332_a
Ignore Unknown Settings Ignore unknown settings
@features_1329_td @features_1333_td
jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE
@features_1330_a @features_1334_a
Custom File Access Mode Custom file access mode
@features_1331_td @features_1335_td
jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws
@features_1332_a @features_1336_a
Database in or Zip File Database in a zip file
@features_1333_td @features_1337_td
jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt; jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt;
@features_1334_td @features_1338_td
jdbc:h2:zip:~/db.zip!/test jdbc:h2:zip:~/db.zip!/test
@features_1335_a @features_1339_a
Compatibility Mode Compatibility mode
@features_1336_td @features_1340_td
jdbc:h2:&lt;url&gt;;MODE=&lt;databaseType&gt; jdbc:h2:&lt;url&gt;;MODE=&lt;databaseType&gt;
@features_1337_td @features_1341_td
jdbc:h2:~/test;MODE=MYSQL jdbc:h2:~/test;MODE=MYSQL
@features_1338_a @features_1342_a
Auto-Reconnect Auto-reconnect
@features_1339_td @features_1343_td
jdbc:h2:&lt;url&gt;;AUTO_RECONNECT=TRUE jdbc:h2:&lt;url&gt;;AUTO_RECONNECT=TRUE
@features_1340_td @features_1344_td
jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE
@features_1341_a @features_1345_a
Automatic Mixed Mode Automatic mixed mode
@features_1342_td @features_1346_td
jdbc:h2:&lt;url&gt;;AUTO_SERVER=TRUE jdbc:h2:&lt;url&gt;;AUTO_SERVER=TRUE
@features_1343_td @features_1347_td
jdbc:h2:~/test;AUTO_SERVER=TRUE jdbc:h2:~/test;AUTO_SERVER=TRUE
@features_1344_a @features_1348_a
Changing Other Settings Changing other settings
@features_1345_td @features_1349_td
jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...] jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...]
@features_1346_td @features_1350_td
jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3 jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
@features_1347_h2 @features_1351_h2
Connecting to an Embedded (Local) Database Connecting to an Embedded (Local) Database
@features_1348_p @features_1352_p
The database URL for connecting to a local database is <code>jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of 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:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of 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 &lt;seconds&gt;. 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 &lt;seconds&gt;. 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 &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent. The number of seconds until a lock timeout exception is thrown can be set separately for each connection using the SQL command SET LOCK_TIMEOUT &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
@features_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: &lt;database&gt;.data.db Format: &lt;database&gt;.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: &lt;database&gt;.index.db Format: &lt;database&gt;.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: &lt;database&gt;.&lt;id&gt;.log.db Format: &lt;database&gt;.&lt;id&gt;.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: &lt;database&gt;.lock.db Format: &lt;database&gt;.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: &lt;database&gt;.trace.db Format: &lt;database&gt;.trace.db
@features_1446_td @features_1450_td
If the file is too big, it is renamed to &lt;database&gt;.trace.db.old If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
@features_1447_td @features_1451_td
1 per database 1 per database
@features_1448_td @features_1452_td
test.14.15.lob.db test.14.15.lob.db
@features_1449_td @features_1453_td
Large object Large object
@features_1450_td @features_1454_td
Contains the data for BLOB or CLOB Contains the data for BLOB or CLOB
@features_1451_td @features_1455_td
Format: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db Format: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db
@features_1452_td @features_1456_td
1 per object 1 per object
@features_1453_td @features_1457_td
test.123.temp.db test.123.temp.db
@features_1454_td @features_1458_td
Temporary file Temporary file
@features_1455_td @features_1459_td
Contains a temporary blob or a large result set Contains a temporary blob or a large result set
@features_1456_td @features_1460_td
Format: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db Format: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db
@features_1457_td @features_1461_td
1 per object 1 per object
@features_1458_td @features_1462_td
test.7.hash.db test.7.hash.db
@features_1459_td @features_1463_td
Hash index file Hash index file
@features_1460_td @features_1464_td
Contains the data for a linear hash index Contains the data for a linear hash index
@features_1461_td @features_1465_td
Format: &lt;database&gt;.&lt;object id&gt;.hash.db Format: &lt;database&gt;.&lt;object id&gt;.hash.db
@features_1462_td @features_1466_td
1 per linear hash index 1 per linear hash index
@features_1463_h3 @features_1467_h3
Moving and Renaming Database Files Moving and Renaming Database Files
@features_1464_p @features_1468_p
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 &lt;database&gt;.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 &lt;database&gt;.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.
@fragments_1000_b @fragments_1000_b
......
...@@ -2731,7 +2731,7 @@ computed column / ベースインデックスの機能 ...@@ -2731,7 +2731,7 @@ computed column / ベースインデックスの機能
非常に高速なデータベースエンジン 非常に高速なデータベースエンジン
@features_1038_li @features_1038_li
無料、ソースコード付き #Open source #無料、ソースコード付き
@features_1039_li @features_1039_li
Javaで記載 Javaで記載
...@@ -2854,13 +2854,13 @@ EXPLAIN PLANをサポート、 洗練されたトレースオプション ...@@ -2854,13 +2854,13 @@ EXPLAIN PLANをサポート、 洗練されたトレースオプション
パフォーマンスを向上させるために、データベースの終了を遅らせるか割り込みを抑制する パフォーマンスを向上させるために、データベースの終了を遅らせるか割り込みを抑制する
@features_1079_li @features_1079_li
Webベースのコンソールアプリケーション (英語、ドイツ語、部分的にフランス語とスペイン語) が自動完備 #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.
@features_1287_th @features_1289_th
トピック トピック
@features_1288_th @features_1290_th
URLフォーマットと例 URLフォーマットと例
@features_1289_a @features_1291_a
エンベッド (ローカル) 接続 エンベッド (ローカル) 接続
@features_1290_td @features_1292_td
jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt; jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;
@features_1291_td @features_1293_td
jdbc:h2:~/test jdbc:h2:~/test
@features_1292_td @features_1294_td
jdbc:h2:file:/data/sample jdbc:h2:file:/data/sample
@features_1293_td
jdbc:h2:file:C:/data/sample (Windowsのみ)
@features_1294_a
インメモリ (プライベート)
@features_1295_td @features_1295_td
jdbc:h2:mem: jdbc:h2:file:C:/data/sample (Windowsのみ)
@features_1296_a @features_1296_a
インメモリ (名付ける) #In-memory (private) #インメモリ (名付ける)
@features_1297_td @features_1297_td
jdbc:h2:mem:&lt;databaseName&gt; jdbc:h2:mem:
@features_1298_td @features_1298_a
jdbc:h2:mem:test_mem #In-memory (named)
@features_1299_a @features_1299_td
TCP/IPを使用したリモート jdbc:h2:mem:&lt;databaseName&gt;
@features_1300_td @features_1300_td
#jdbc:h2:tcp://&lt;server&gt;[:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt; jdbc:h2:mem:test_mem
@features_1301_td @features_1301_a
#jdbc:h2:tcp://localhost/~/test #Server mode (remote connections)
@features_1302_td @features_1302_a
#jdbc:h2:tcp://dbserv:8084/~/sample #using TCP/IP
@features_1303_a @features_1303_td
SSL/TLSを使用したリモート #jdbc:h2:tcp://&lt;server&gt;[:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt;
@features_1304_td @features_1304_td
jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt; #jdbc:h2:tcp://localhost/~/test #jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt;
@features_1305_td @features_1305_td
#jdbc:h2:ssl://secureserv:8085/~/sample; #jdbc:h2:tcp://dbserv:8084/~/sample
@features_1306_a @features_1306_a
暗号化ファイルの使用 #Server mode (remote connections) #暗号化ファイルの使用
@features_1307_td @features_1307_a
jdbc:h2:&lt;url&gt;;CIPHER=[AES|XTEA] #using SSL/TLS
@features_1308_td @features_1308_td
#jdbc:h2:ssl://secureserv/~/testdb;CIPHER=AES jdbc:h2:ssl://&lt;server&gt;[:&lt;port&gt;]/&lt;databaseName&gt;
@features_1309_td @features_1309_td
jdbc:h2:file:~/secure;CIPHER=XTEA #jdbc:h2:ssl://secureserv:8085/~/sample; #jdbc:h2:file:~/secure;CIPHER=XTEA
@features_1310_a @features_1310_a
ファイルロックメソッド #Using encrypted files #ファイルロックメソッド
@features_1311_td @features_1311_td
jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET} jdbc:h2:&lt;url&gt;;CIPHER=[AES|XTEA]
@features_1312_td @features_1312_td
jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO #jdbc:h2:ssl://secureserv/~/testdb;CIPHER=AES #jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO
@features_1313_td @features_1313_td
jdbc:h2:file:~/private;CIPHER=XTEA;FILE_LOCK=SOCKET jdbc:h2:file:~/secure;CIPHER=XTEA
@features_1314_a @features_1314_a
すでに存在する場合は起動のみ #File locking methods #すでに存在する場合は起動のみ
@features_1315_td @features_1315_td
jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE jdbc:h2:&lt;url&gt;;FILE_LOCK={NO|FILE|SOCKET}
@features_1316_td @features_1316_td
jdbc:h2:file:~/quickAndDirty;FILE_LOCK=NO
@features_1317_td
jdbc:h2:file:~/private;CIPHER=XTEA;FILE_LOCK=SOCKET
@features_1318_a
#Only open if it already exists
@features_1319_td
jdbc:h2:&lt;url&gt;;IFEXISTS=TRUE
@features_1320_td
jdbc:h2:file:~/sample;IFEXISTS=TRUE jdbc:h2:file:~/sample;IFEXISTS=TRUE
@features_1317_a @features_1321_a
VMが終了した時、データベースを終了しない #Don't close the database when the VM exits
@features_1318_td @features_1322_td
jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE jdbc:h2:&lt;url&gt;;DB_CLOSE_ON_EXIT=FALSE
@features_1319_a @features_1323_a
ユーザー名、及びパスワード #User name and/or password
@features_1320_td @features_1324_td
jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;] jdbc:h2:&lt;url&gt;[;USER=&lt;username&gt;][;PASSWORD=&lt;value&gt;]
@features_1321_td @features_1325_td
jdbc:h2:file:~/sample;USER=sa;PASSWORD=123 jdbc:h2:file:~/sample;USER=sa;PASSWORD=123
@features_1322_a @features_1326_a
ログインデックスの修正 #Log index changes
@features_1323_td @features_1327_td
jdbc:h2:&lt;url&gt;;LOG=2 jdbc:h2:&lt;url&gt;;LOG=2
@features_1324_td @features_1328_td
jdbc:h2:file:~/sample;LOG=2 jdbc:h2:file:~/sample;LOG=2
@features_1325_a @features_1329_a
デバックトレースの設定 #Debug trace settings
@features_1326_td @features_1330_td
jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt; jdbc:h2:&lt;url&gt;;TRACE_LEVEL_FILE=&lt;level 0..3&gt;
@features_1327_td @features_1331_td
jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3 jdbc:h2:file:~/sample;TRACE_LEVEL_FILE=3
@features_1328_a @features_1332_a
未知の設定を無視 #Ignore unknown settings
@features_1329_td @features_1333_td
jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE jdbc:h2:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS=TRUE
@features_1330_a @features_1334_a
カスタムファイル アクセスモード #Custom file access mode
@features_1331_td @features_1335_td
jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws jdbc:h2:&lt;url&gt;;ACCESS_MODE_LOG=rws;ACCESS_MODE_DATA=rws
@features_1332_a @features_1336_a
#Database in or Zip File #Database in a zip file
@features_1333_td @features_1337_td
#jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt; #jdbc:h2:zip:&lt;zipFileName&gt;!/&lt;databaseName&gt;
@features_1334_td @features_1338_td
#jdbc:h2:zip:~/db.zip!/test #jdbc:h2:zip:~/db.zip!/test
@features_1335_a @features_1339_a
#Compatibility Mode #Compatibility mode
@features_1336_td @features_1340_td
#jdbc:h2:&lt;url&gt;;MODE=&lt;databaseType&gt; #jdbc:h2:&lt;url&gt;;MODE=&lt;databaseType&gt;
@features_1337_td @features_1341_td
#jdbc:h2:~/test;MODE=MYSQL #jdbc:h2:~/test;MODE=MYSQL
@features_1338_a @features_1342_a
#Auto-Reconnect #Auto-reconnect
@features_1339_td @features_1343_td
#jdbc:h2:&lt;url&gt;;AUTO_RECONNECT=TRUE #jdbc:h2:&lt;url&gt;;AUTO_RECONNECT=TRUE
@features_1340_td @features_1344_td
#jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE #jdbc:h2:tcp://localhost/~/test;AUTO_RECONNECT=TRUE
@features_1341_a @features_1345_a
#Automatic Mixed Mode #Automatic mixed mode
@features_1342_td @features_1346_td
#jdbc:h2:&lt;url&gt;;AUTO_SERVER=TRUE #jdbc:h2:&lt;url&gt;;AUTO_SERVER=TRUE #jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
@features_1343_td @features_1347_td
#jdbc:h2:~/test;AUTO_SERVER=TRUE #jdbc:h2:~/test;AUTO_SERVER=TRUE
@features_1344_a @features_1348_a
他の設定の変更 #Changing other settings
@features_1345_td @features_1349_td
jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...] jdbc:h2:&lt;url&gt;;&lt;setting&gt;=&lt;value&gt;[;&lt;setting&gt;=&lt;value&gt;...]
@features_1346_td @features_1350_td
jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3 jdbc:h2:file:~/sample;TRACE_LEVEL_SYSTEM_OUT=3
@features_1347_h2 @features_1351_h2
エンベッド (ローカル) データベースに接続 エンベッド (ローカル) データベースに接続
@features_1348_p @features_1352_p
#The database URL for connecting to a local database is <code>jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of 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:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in: jdbc:h2:~/test. #時々、複数の接続が同じメモリオンリーデータベースを必要とします。このケースでは、データベースのURLに名前が含まれていなければなりません。例: <code>jdbc:h2:mem:db1</code> この方法での同じデータベースのアクセスは、同じ仮想マシンとClassLoader環境内でのみ動作します。
@features_1349_h2 @features_1353_h2
メモリオンリーデータベース メモリオンリーデータベース
@features_1350_p @features_1354_p
特定の使用方法では (例: rapid prototyping、テスト、高パフォーマンスオペレーション、読み取り専用データベース)、データは持続する (変化する) 必要は全くないかもしれません。このデータベースは、データが持続しない際にメモリオンリーモードをサポートします。 #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
一部ケースでは、メモリオンリーデータベースへの接続はひとつの接続のみ必要とされます。これは、開かれるデータベースがプライベートだということを意味しています。このケースでは、データベースURLは <CODE>jdbc:h2:mem:</CODE> です。同じ仮想マシン内で二つの接続が開いているというのは、二つの異なった (プライベートの) データベースが開いているという意味です。 一部ケースでは、メモリオンリーデータベースへの接続はひとつの接続のみ必要とされます。これは、開かれるデータベースがプライベートだということを意味しています。このケースでは、データベースURLは <CODE>jdbc:h2:mem:</CODE> です。同じ仮想マシン内で二つの接続が開いているというのは、二つの異なった (プライベートの) データベースが開いているという意味です。
@features_1352_p @features_1356_p
時々、複数の接続が同じメモリオンリーデータベースを必要とします。このケースでは、データベースのURLに名前が含まれていなければなりません。例: <code>jdbc:h2:mem:db1</code> この方法での同じデータベースのアクセスは、同じ仮想マシンとClassLoader環境内でのみ動作します。 時々、複数の接続が同じメモリオンリーデータベースを必要とします。このケースでは、データベースのURLに名前が含まれていなければなりません。例: <code>jdbc:h2:mem:db1</code> この方法での同じデータベースのアクセスは、同じ仮想マシンとClassLoader環境内でのみ動作します。
@features_1353_p @features_1357_p
TCP/IPまたは、SSL/TLSを使用して、メモリオンリーデータベースに間接的に (または、同じマシンの複数のプロセスから) 接続することも可能です。データベースURLの例: <code>jdbc:h2:tcp://localhost/mem:db1</code> (プライベートデータベースを間接的に使用することも可能です) TCP/IPまたは、SSL/TLSを使用して、メモリオンリーデータベースに間接的に (または、同じマシンの複数のプロセスから) 接続することも可能です。データベースURLの例: <code>jdbc:h2:tcp://localhost/mem:db1</code> (プライベートデータベースを間接的に使用することも可能です)
@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
データベースファイルロック データベースファイルロック
@features_1364_p @features_1368_p
データベースが開かれるときはいつも、データベースが使用中であると他のプロセスに合図するためにロックファイルが作成されます。もしデータベースが閉じられるか、データベースを開いたプロセスが終了するなら、ロックファイルは削除されます。 データベースが開かれるときはいつも、データベースが使用中であると他のプロセスに合図するためにロックファイルが作成されます。もしデータベースが閉じられるか、データベースを開いたプロセスが終了するなら、ロックファイルは削除されます。
@features_1365_p @features_1369_p
以下のファイルロックメソッドが提供されます: 以下のファイルロックメソッドが提供されます:
@features_1366_li @features_1370_li
デフォルトメソッドは "file" で、データベースファイルを保護するために、watchdogスレッドを使用します。watchdogは、ロックファイルをそれぞれ秒単位で読み込みます。 デフォルトメソッドは "file" で、データベースファイルを保護するために、watchdogスレッドを使用します。watchdogは、ロックファイルをそれぞれ秒単位で読み込みます。
@features_1367_li @features_1371_li
二つめのメソッドは "socket" で、サーバーソケットを開きます。ソケットメソッドは、ロックファイルを秒単位で読むことを必要としていません。ソケットメソッドは、データベースファイルがひとつの (いつも同じ) コンピューターのみによってアクセスされる場合にのみ使用されます。 二つめのメソッドは "socket" で、サーバーソケットを開きます。ソケットメソッドは、ロックファイルを秒単位で読むことを必要としていません。ソケットメソッドは、データベースファイルがひとつの (いつも同じ) コンピューターのみによってアクセスされる場合にのみ使用されます。
@features_1368_li @features_1372_li
ファイルロッキングなしでデータベースを開始することも可能です; このケースでは、データベースファイルを保護するのはアプリケーション次第です。 ファイルロッキングなしでデータベースを開始することも可能です; このケースでは、データベースファイルを保護するのはアプリケーション次第です。
@features_1369_p @features_1373_p
異なったファイルロックメソッドでデータベースを開くには、"FILE_LOCK" パラメータを使用します。以下のコードは "socket" ロックメソッドのデータベースを開きます: 異なったファイルロックメソッドでデータベースを開くには、"FILE_LOCK" パラメータを使用します。以下のコードは "socket" ロックメソッドのデータベースを開きます:
@features_1370_p @features_1374_p
以下のコードは、データベースにロックファイルを全く作らないよう強要させます。これは、データ破損を導く可能性のある、同じデータベースを開くことができる他のプロセスのように、安全ではないということに注意して下さい: 以下のコードは、データベースにロックファイルを全く作らないよう強要させます。これは、データ破損を導く可能性のある、同じデータベースを開くことができる他のプロセスのように、安全ではないということに注意して下さい:
@features_1371_p @features_1375_p
アルゴリズムについての詳しい情報は、進化したトピックス のファイルロックプロトコルをご覧下さい。 アルゴリズムについての詳しい情報は、進化したトピックス のファイルロックプロトコルをご覧下さい。
@features_1372_h2 @features_1376_h2
すでに存在する場合のみ、データベースを開く すでに存在する場合のみ、データベースを開く
@features_1373_p @features_1377_p
デフォルトでは、アプリケーションが <code>DriverManager.getConnection(url,...)</code> を呼び出し、URLで指定されたデータベースがまだ存在しない時、 新しい (空の) データベースが作成されます。ある状況では、もしすでにデータベースが存在するのであれば、新しいデータベースの作成を制限して、データベースを開くだけにした方がよいでしょう。<code>;ifexists=true</code> をURLに追加することによって可能になります。このケースでは、もしデータベースがまだ存在していなければ、接続しようとした時に例外が投げられます。接続は、データベースがすでに存在する時のみ成功します。完全なURLは次のようです: デフォルトでは、アプリケーションが <code>DriverManager.getConnection(url,...)</code> を呼び出し、URLで指定されたデータベースがまだ存在しない時、 新しい (空の) データベースが作成されます。ある状況では、もしすでにデータベースが存在するのであれば、新しいデータベースの作成を制限して、データベースを開くだけにした方がよいでしょう。<code>;ifexists=true</code> をURLに追加することによって可能になります。このケースでは、もしデータベースがまだ存在していなければ、接続しようとした時に例外が投げられます。接続は、データベースがすでに存在する時のみ成功します。完全なURLは次のようです:
@features_1374_h2 @features_1378_h2
データベースを終了する データベースを終了する
@features_1375_h3 @features_1379_h3
データベースの遅延終了 データベースの遅延終了
@features_1376_p @features_1380_p
通常、データベースへの最後の接続が閉じられた時、データベースが終了されます。一部状況では、例えば、可能ではない時に接続をつなげたままにしておくことは、アプリケーションを減速させます。SQLステートメントの SET DB_CLOSE_DELAY &lt;seconds&gt; でデータベースの自動終了を遅らせるか、または無効にすることができます。secondsには、最後の接続が閉じられた後データベースを接続したままの状態に保つため、秒数を指定します。例えば、次のステートメントはデータベースを10秒間開かれた状態に保ちます: 通常、データベースへの最後の接続が閉じられた時、データベースが終了されます。一部状況では、例えば、可能ではない時に接続をつなげたままにしておくことは、アプリケーションを減速させます。SQLステートメントの SET DB_CLOSE_DELAY &lt;seconds&gt; でデータベースの自動終了を遅らせるか、または無効にすることができます。secondsには、最後の接続が閉じられた後データベースを接続したままの状態に保つため、秒数を指定します。例えば、次のステートメントはデータベースを10秒間開かれた状態に保ちます:
@features_1377_p @features_1381_p
値の-1は、データベースは決して自動的に閉じられないということを意味します。値の0はデフォルトで、最後の接続が終了した時データベースが終了するということを意味します。この設定は永続的で、管理者のみが設定することができます。データベースのURL内で値を設定することが可能です: <code>jdbc:h2:~/test;DB_CLOSE_DELAY=10</code> 値の-1は、データベースは決して自動的に閉じられないということを意味します。値の0はデフォルトで、最後の接続が終了した時データベースが終了するということを意味します。この設定は永続的で、管理者のみが設定することができます。データベースのURL内で値を設定することが可能です: <code>jdbc:h2:~/test;DB_CLOSE_DELAY=10</code>
@features_1378_h3 @features_1382_h3
VMが終了した時、データベースを終了しない VMが終了した時、データベースを終了しない
@features_1379_p @features_1383_p
デフォルトでは、データベースは最後の接続が閉じられた時に終了されます。しかし、最後の接続が決して閉じられなければ、仮想マシンが正常に終了する時にデータベースは閉じられます。これはshutdown hookを使うことによって行われます。一部状況では、データベースはこのケースで終了されてはいけません。例えば、仮想マシンが終了している時にデータベースがまだ使われている場合です (例として、シャットダウンプロセスをデータベースに保存するため)。このケースでは、データベースURLでデータベースの自動終了を無効にすることが可能です。最初の接続は (ひとつはデータベースを開始するもの) データベースURLにオプションを設定する必要があります (設定を後で変更することは不可能です)。VMが終了する時、データベースの終了を無効にするためのデータベースURLです: デフォルトでは、データベースは最後の接続が閉じられた時に終了されます。しかし、最後の接続が決して閉じられなければ、仮想マシンが正常に終了する時にデータベースは閉じられます。これはshutdown hookを使うことによって行われます。一部状況では、データベースはこのケースで終了されてはいけません。例えば、仮想マシンが終了している時にデータベースがまだ使われている場合です (例として、シャットダウンプロセスをデータベースに保存するため)。このケースでは、データベースURLでデータベースの自動終了を無効にすることが可能です。最初の接続は (ひとつはデータベースを開始するもの) データベースURLにオプションを設定する必要があります (設定を後で変更することは不可能です)。VMが終了する時、データベースの終了を無効にするためのデータベースURLです:
@features_1380_h2 @features_1384_h2
ログインデックスの修正 ログインデックスの修正
@features_1381_p @features_1385_p
通常、インデックスファイルの変更はパフォーマンスのために記録されません。データベースを開いた時に、インデックスファイルが破損しているか、無くなっていたら、データから作り直されます。停電、またはプログラムの異常終了のため、データベースが正しく終了されなかった時、インデックスファイルは破損されます。一部状況では、例えば、非常に大きなデータベースを使用している時 (数百MB以上)、インデックスファイルが再作成されるのにはとても時間がかかります。それらの状況では、インデックスファイルの変更を記録しておいた方がよいでしょう。そうすることによって、破損されたインデックスファイルの回復が速くなります。ログインデックスの修正を可能にするためには、jdbc:h2:~/test;LOG=2 のように、URLに LOG=2 を追加して下さい。接続する時に、この設定が指定されます。このオプションを使用する時、データベースのアップデートパフォーマンスは低下するでしょう。 通常、インデックスファイルの変更はパフォーマンスのために記録されません。データベースを開いた時に、インデックスファイルが破損しているか、無くなっていたら、データから作り直されます。停電、またはプログラムの異常終了のため、データベースが正しく終了されなかった時、インデックスファイルは破損されます。一部状況では、例えば、非常に大きなデータベースを使用している時 (数百MB以上)、インデックスファイルが再作成されるのにはとても時間がかかります。それらの状況では、インデックスファイルの変更を記録しておいた方がよいでしょう。そうすることによって、破損されたインデックスファイルの回復が速くなります。ログインデックスの修正を可能にするためには、jdbc:h2:~/test;LOG=2 のように、URLに LOG=2 を追加して下さい。接続する時に、この設定が指定されます。このオプションを使用する時、データベースのアップデートパフォーマンスは低下するでしょう。
@features_1382_h2 @features_1386_h2
未知の設定を無視 未知の設定を無視
@features_1383_p @features_1387_p
データベースに接続する時、いくつかのアプリケーションが (例えば、OpenOffice.org Base) いくつかの追加パラメータを渡します。なぜそれらのパラメータが渡されるのかは知られていません。PREFERDOSLIKELINEENDS と IGNOREDRIVERPRIVILEGES はパラメータの例で、それらは、OpenOffice.orgとの互換性を改良するために単に無視されます。もしデータベースに接続する時、アプリケーションが他のパラメータを渡していたら、通常データベースは、 パラメータはサポートされていません、という例外を投げます。データベースURLに ;IGNORE_UNKNOWN_SETTINGS=TRUE を追加することで、このようなパラメータを無視することが可能です。 データベースに接続する時、いくつかのアプリケーションが (例えば、OpenOffice.org Base) いくつかの追加パラメータを渡します。なぜそれらのパラメータが渡されるのかは知られていません。PREFERDOSLIKELINEENDS と IGNOREDRIVERPRIVILEGES はパラメータの例で、それらは、OpenOffice.orgとの互換性を改良するために単に無視されます。もしデータベースに接続する時、アプリケーションが他のパラメータを渡していたら、通常データベースは、 パラメータはサポートされていません、という例外を投げます。データベースURLに ;IGNORE_UNKNOWN_SETTINGS=TRUE を追加することで、このようなパラメータを無視することが可能です。
@features_1384_h2 @features_1388_h2
接続が開始された時に他の設定を変更する 接続が開始された時に他の設定を変更する
@features_1385_p @features_1389_p
すでに記述された設定に加えて (暗号、ファイルロック、データベースの存在、ユーザー、パスワード)、他のデータベースの設定は、データベースURLの中で渡すことができます。<CODE>SET setting value</CODE>ステートメントを接続直後に実行するのと同じように 、<CODE>setting=value</CODE> をURLの最後に追加します。このデータベースによってサポートされている設定の一覧は、SQL文法のドキュメントをご覧下さい。 すでに記述された設定に加えて (暗号、ファイルロック、データベースの存在、ユーザー、パスワード)、他のデータベースの設定は、データベースURLの中で渡すことができます。<CODE>SET setting value</CODE>ステートメントを接続直後に実行するのと同じように 、<CODE>setting=value</CODE> をURLの最後に追加します。このデータベースによってサポートされている設定の一覧は、SQL文法のドキュメントをご覧下さい。
@features_1386_h2 @features_1390_h2
カスタムファイル アクセスモード カスタムファイル アクセスモード
@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
詳細は <a href="advanced.html#durability_problems">永続性問題</a> をご覧下さい。 多くのオペレーティングシステムでは、アクセスモード "rws" において、データがディスクに書かれていることを保証しません。 詳細は <a href="advanced.html#durability_problems">永続性問題</a> をご覧下さい。 多くのオペレーティングシステムでは、アクセスモード "rws" において、データがディスクに書かれていることを保証しません。
@features_1389_h2 @features_1393_h2
複数の接続 複数の接続
@features_1390_h3 @features_1394_h3
同時に複数のデータベースを開く 同時に複数のデータベースを開く
@features_1391_p @features_1395_p
アプリケーションは、同じデータベースへの複数の接続を含め、複数のデータベースを同時に開くことができます。開くデータベースの数は、利用可能なメモリによってのみ制限されています。 アプリケーションは、同じデータベースへの複数の接続を含め、複数のデータベースを同時に開くことができます。開くデータベースの数は、利用可能なメモリによってのみ制限されています。
@features_1392_h3 @features_1396_h3
>同じデータベースへの複数の接続: クライアント/サーバー >同じデータベースへの複数の接続: クライアント/サーバー
@features_1393_p @features_1397_p
異なったプロセス、またはコンピューターから同時に同じデータベースにアクセスしたい場合、クライアント/サーバー モードを使用することが必要です。このケースでは、ひとつのプロセスがサーバーとして動作し、他のプロセスは (同様に他のコンピューターに属することができます) TCP/IP (または改善されたセキュリティ用のTCP/IPの上のSSL/TLS) を通してサーバーに接続します。 異なったプロセス、またはコンピューターから同時に同じデータベースにアクセスしたい場合、クライアント/サーバー モードを使用することが必要です。このケースでは、ひとつのプロセスがサーバーとして動作し、他のプロセスは (同様に他のコンピューターに属することができます) TCP/IP (または改善されたセキュリティ用のTCP/IPの上のSSL/TLS) を通してサーバーに接続します。
@features_1394_h3 @features_1398_h3
マルチスレッドサポート マルチスレッドサポート
@features_1395_p @features_1399_p
このデータベースは安全なマルチスレッドです。これは、アプリケーションがマルチスレッドならば、データベースへの同時アクセスに関して心配する必要がない、ということを意味しています。本質的に、同じデータベースへのほとんどのリクエストは同時に動きます。アプリケーションは、同時に同じデータベースにアクセスするマルチスレッドを使用することができますが、ひとつのスレッドが処理時間の長いクエリーを実行しているなら、他のスレッドは待つ必要があります。 このデータベースは安全なマルチスレッドです。これは、アプリケーションがマルチスレッドならば、データベースへの同時アクセスに関して心配する必要がない、ということを意味しています。本質的に、同じデータベースへのほとんどのリクエストは同時に動きます。アプリケーションは、同時に同じデータベースにアクセスするマルチスレッドを使用することができますが、ひとつのスレッドが処理時間の長いクエリーを実行しているなら、他のスレッドは待つ必要があります。
@features_1396_h3 @features_1400_h3
ロック、ロックタイムアウト、デッドロック ロック、ロックタイムアウト、デッドロック
@features_1397_p @features_1401_p
データの一貫した状態をそれぞれの接続に与えるために、データベースはテーブルレベルでのロックを使用します。二種類のロックがあります: リードロック (共有ロック) とライトロック (排他ロック) です。もし、接続がテーブルから読み込みたい場合で、テーブルにライトロックがない場合に、リードロックをテーブルに追加します。もしライトロックがあれば、この接続はロックを解除するために他の接続を待ちます。接続が指定された時間までにロックを取得できなければ、ロックタイムアウトの例外が投げられます。 データの一貫した状態をそれぞれの接続に与えるために、データベースはテーブルレベルでのロックを使用します。二種類のロックがあります: リードロック (共有ロック) とライトロック (排他ロック) です。もし、接続がテーブルから読み込みたい場合で、テーブルにライトロックがない場合に、リードロックをテーブルに追加します。もしライトロックがあれば、この接続はロックを解除するために他の接続を待ちます。接続が指定された時間までにロックを取得できなければ、ロックタイムアウトの例外が投げられます。
@features_1398_p @features_1402_p
通常、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 &lt;milliseconds&gt; を使用して、ロックタイムアウトの例外が投げられるまでの秒数を、それぞれの接続ごとに別々に設定することができます。SQLコマンド SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、初期のロックタイムアウト (新しい接続に使用されるタイムアウト) を設定することができます。デフォルトのロックタイムアウトは永続的です。 SQLコマンド SET LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、ロックタイムアウトの例外が投げられるまでの秒数を、それぞれの接続ごとに別々に設定することができます。SQLコマンド SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt; を使用して、初期のロックタイムアウト (新しい接続に使用されるタイムアウト) を設定することができます。デフォルトのロックタイムアウトは永続的です。
@features_1417_h2 @features_1421_h2
データベースファイルレイアウト データベースファイルレイアウト
@features_1418_p @features_1422_p
永続的なデータベースのために作成された多くのファイルがあります。一部のデータベースを除いて、全てのテーブルと (または) インデックスが自身のファイル内に保存されているわけではありません。その代りに、通常次のファイルのみが作成されます: データファイル、インデックスファイル、ログファイル、データベースロックファイル (データベースが使われている間のみ存在します)。それに加えて、ファイルはそれぞれの大きなオブジェクト (CLOB/BLOB) のために作成されます。各ライナーインデックスのためのファイル、大きなresult setのためのテンポラリーファイルです。データベーストレースオプションが有効の場合、トレースファイルが作成されます。次のファイルはデータベースによって作成されます: 永続的なデータベースのために作成された多くのファイルがあります。一部のデータベースを除いて、全てのテーブルと (または) インデックスが自身のファイル内に保存されているわけではありません。その代りに、通常次のファイルのみが作成されます: データファイル、インデックスファイル、ログファイル、データベースロックファイル (データベースが使われている間のみ存在します)。それに加えて、ファイルはそれぞれの大きなオブジェクト (CLOB/BLOB) のために作成されます。各ライナーインデックスのためのファイル、大きなresult setのためのテンポラリーファイルです。データベーストレースオプションが有効の場合、トレースファイルが作成されます。次のファイルはデータベースによって作成されます:
@features_1419_th @features_1423_th
ファイル名 ファイル名
@features_1420_th @features_1424_th
説明 説明
@features_1421_th @features_1425_th
ファイル数 ファイル数
@features_1422_td @features_1426_td
test.data.db test.data.db
@features_1423_td @features_1427_td
データファイル データファイル
@features_1424_td @features_1428_td
全てのテーブルのデータを含む 全てのテーブルのデータを含む
@features_1425_td @features_1429_td
フォーマット: &lt;database&gt;.data.db フォーマット: &lt;database&gt;.data.db
@features_1426_td @features_1430_td
データベースごとに1ファイル データベースごとに1ファイル
@features_1427_td @features_1431_td
test.index.db test.index.db
@features_1428_td @features_1432_td
インデックスファイル インデックスファイル
@features_1429_td @features_1433_td
全ての (btree) インデックスのデータを含む 全ての (btree) インデックスのデータを含む
@features_1430_td @features_1434_td
フォーマット: &lt;database&gt;.index.db フォーマット: &lt;database&gt;.index.db
@features_1431_td @features_1435_td
データベースごとに1ファイル データベースごとに1ファイル
@features_1432_td @features_1436_td
test.0.log.db test.0.log.db
@features_1433_td @features_1437_td
ログファイル ログファイル
@features_1434_td @features_1438_td
ログファイルはリカバリーのために使われる ログファイルはリカバリーのために使われる
@features_1435_td @features_1439_td
フォーマット: &lt;database&gt;.&lt;id&gt;.log.db フォーマット: &lt;database&gt;.&lt;id&gt;.log.db
@features_1436_td @features_1440_td
データベースごとに0ファイル以上 データベースごとに0ファイル以上
@features_1437_td @features_1441_td
test.lock.db test.lock.db
@features_1438_td @features_1442_td
データベースロックファイル データベースロックファイル
@features_1439_td @features_1443_td
データベースが開かれている時のみ存在 データベースが開かれている時のみ存在
@features_1440_td @features_1444_td
フォーマット: &lt;database&gt;.lock.db フォーマット: &lt;database&gt;.lock.db
@features_1441_td @features_1445_td
データベースごとに1ファイル データベースごとに1ファイル
@features_1442_td @features_1446_td
test.trace.db test.trace.db
@features_1443_td @features_1447_td
トレースファイル トレースファイル
@features_1444_td @features_1448_td
トレース情報を含む トレース情報を含む
@features_1445_td @features_1449_td
フォーマット: &lt;database&gt;.trace.db フォーマット: &lt;database&gt;.trace.db
@features_1446_td @features_1450_td
ファイルが大きすぎる場合、&lt;database&gt;.trace.db.old に改名される ファイルが大きすぎる場合、&lt;database&gt;.trace.db.old に改名される
@features_1447_td @features_1451_td
データベースごとに1ファイル データベースごとに1ファイル
@features_1448_td @features_1452_td
test.14.15.lob.db test.14.15.lob.db
@features_1449_td @features_1453_td
大きなオブジェクト 大きなオブジェクト
@features_1450_td @features_1454_td
BLOB、またはCLOBのデータを含む BLOB、またはCLOBのデータを含む
@features_1451_td @features_1455_td
フォーマット: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db フォーマット: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db
@features_1452_td @features_1456_td
オブジェクトごとに1ファイル オブジェクトごとに1ファイル
@features_1453_td @features_1457_td
test.123.temp.db test.123.temp.db
@features_1454_td @features_1458_td
テンポラリーファイル テンポラリーファイル
@features_1455_td @features_1459_td
テンポラリーblob、または大きなresult setを含む テンポラリーblob、または大きなresult setを含む
@features_1456_td @features_1460_td
フォーマット: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db フォーマット: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db
@features_1457_td @features_1461_td
オブジェクトごとに1ファイル オブジェクトごとに1ファイル
@features_1458_td @features_1462_td
test.7.hash.db test.7.hash.db
@features_1459_td @features_1463_td
ハッシュインデックスファイル ハッシュインデックスファイル
@features_1460_td @features_1464_td
ライナーハッシュインデックスのデータを含む ライナーハッシュインデックスのデータを含む
@features_1461_td @features_1465_td
フォーマット: &lt;database&gt;.&lt;object id&gt;.hash.db フォーマット: &lt;database&gt;.&lt;object id&gt;.hash.db
@features_1462_td @features_1466_td
ライナーハッシュインデックスごとに1ファイル ライナーハッシュインデックスごとに1ファイル
@features_1463_h3 @features_1467_h3
データベースファイルの移動と改名 データベースファイルの移動と改名
@features_1464_p @features_1468_p
データベースの名前と位置は、データベース名の中には保存されません。 データベースの名前と位置は、データベース名の中には保存されません。
@features_1465_p @features_1469_p
データベースが閉じられている間、ファイルは他のディレクトリに移動することができ、同様にファイル名を変えることもできます (全てのファイルが同じ名前で始まる必要があります)。 データベースが閉じられている間、ファイルは他のディレクトリに移動することができ、同様にファイル名を変えることもできます (全てのファイルが同じ名前で始まる必要があります)。
@features_1466_p @features_1470_p
ファイルにはプラットホーム固有のデータがないので、問題なく他のオペレーティングシステムに移動することができます。 ファイルにはプラットホーム固有のデータがないので、問題なく他のオペレーティングシステムに移動することができます。
@features_1467_h3 @features_1471_h3
バックアップ バックアップ
@features_1468_p @features_1472_p
データベースが閉じられている時、データベースファイルのバックアップをとることが可能です。インデックスファイルはバックアップをとる必要はありません。なぜなら、インデックスファイルは冗長なデータを含み、もしファイルが存在しなければ自動的に再作成されるからです。 データベースが閉じられている時、データベースファイルのバックアップをとることが可能です。インデックスファイルはバックアップをとる必要はありません。なぜなら、インデックスファイルは冗長なデータを含み、もしファイルが存在しなければ自動的に再作成されるからです。
@features_1469_p @features_1473_p
データベースが動作している間にバックアップデータをとるために、SQLコマンド SCRIPTを使うことができます。 データベースが動作している間にバックアップデータをとるために、SQLコマンド SCRIPTを使うことができます。
@features_1470_h2 @features_1474_h2
ログとリカバリー ログとリカバリー
@features_1471_p @features_1475_p
データベースでデータが修正され、それらの変更がコミットされた時はいつでも、変更はディスクに記録されます (インメモリオブジェクトを除いて)。データファイル自体への変更は通常、ディスクアクセスを最適化するために後で書かれています。もし電源異常があった場合、データファイルとインデックスファイルはアップデートされません。しかし、変更がログファイルに書かれていれば、次回データベースを開いた時に、ログファイルに書かれた変更は自動的に再び適用されます。 データベースでデータが修正され、それらの変更がコミットされた時はいつでも、変更はディスクに記録されます (インメモリオブジェクトを除いて)。データファイル自体への変更は通常、ディスクアクセスを最適化するために後で書かれています。もし電源異常があった場合、データファイルとインデックスファイルはアップデートされません。しかし、変更がログファイルに書かれていれば、次回データベースを開いた時に、ログファイルに書かれた変更は自動的に再び適用されます。
@features_1472_p @features_1476_p
インデックスファイルのアップデートはデフォルトでは記録されないことに注意して下さい。もしデータベースが開かれて、リカバリーが必要だとされたら、インデックスファイルは最初から作り替えられます。 インデックスファイルのアップデートはデフォルトでは記録されないことに注意して下さい。もしデータベースが開かれて、リカバリーが必要だとされたら、インデックスファイルは最初から作り替えられます。
@features_1473_p @features_1477_p
通常、データベースごとにたったひとつのログファイルがあります。このファイルは、データベースが正常に終了されるまで増大し、削除されます。また、ファイルが大きくなりすぎたら、データベースは別のログファイルに交換します (より大きなIDで)。CHECKPOINT コマンドを使用することによって、ログの切り替えを強制することが可能です。 通常、データベースごとにたったひとつのログファイルがあります。このファイルは、データベースが正常に終了されるまで増大し、削除されます。また、ファイルが大きくなりすぎたら、データベースは別のログファイルに交換します (より大きなIDで)。CHECKPOINT コマンドを使用することによって、ログの切り替えを強制することが可能です。
@features_1474_p @features_1478_p
checksumのレコードが合わないために (例えば、別のアプリケーションからファイルが編集された場合) データベースファイルが破損したら、データベースをリカバリーモードで開くことができます。このケースでは、データベースのエラーは記録されますが、投げられません。データベースはスクリプトまでバックアップをとり、可能な限り早く再構築します。データベースをリカバリーモードで開くために、jdbc:h2:~/test;RECOVER=1 のように、RECOVER=1 を含むデータベースURLを使用します。この場合、インデックスは再構築され、サマリー (アロケーションテーブルのオブジェクト)は読まれないため、データベースを開くのに時間がかかります。 checksumのレコードが合わないために (例えば、別のアプリケーションからファイルが編集された場合) データベースファイルが破損したら、データベースをリカバリーモードで開くことができます。このケースでは、データベースのエラーは記録されますが、投げられません。データベースはスクリプトまでバックアップをとり、可能な限り早く再構築します。データベースをリカバリーモードで開くために、jdbc:h2:~/test;RECOVER=1 のように、RECOVER=1 を含むデータベースURLを使用します。この場合、インデックスは再構築され、サマリー (アロケーションテーブルのオブジェクト)は読まれないため、データベースを開くのに時間がかかります。
@features_1475_h2 @features_1479_h2
互換性 互換性
@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
互換モード 互換モード
@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
トレースオプションを使用する トレースオプションを使用する
@features_1525_p @features_1529_p
アプリケーション内の問題を見つけるために、時々、何のデータベースオペレーションがどこで実行されているかを知るのは良い方法です。このデータベースは次のトレースの特徴を提供します: アプリケーション内の問題を見つけるために、時々、何のデータベースオペレーションがどこで実行されているかを知るのは良い方法です。このデータベースは次のトレースの特徴を提供します:
@features_1526_li @features_1530_li
System.out と (または) ファイルをトレースする System.out と (または) ファイルをトレースする
@features_1527_li @features_1531_li
トレースレベル OFF、ERROR、INFO と DEBUG をサポート トレースレベル OFF、ERROR、INFO と DEBUG をサポート
@features_1528_li @features_1532_li
トレースファイルの最大サイズの設定が可能 トレースファイルの最大サイズの設定が可能
@features_1529_li @features_1533_li
Javaコード生成が可能 Javaコード生成が可能
@features_1530_li @features_1534_li
手動でファイルを作成することによって、ランタイムでトレースが可能 手動でファイルを作成することによって、ランタイムでトレースが可能
@features_1531_h3 @features_1535_h3
トレースオプション トレースオプション
@features_1532_p @features_1536_p
トレースオプションを可能にする簡単な方法は、データベースURLにトレースオプションを設定することです。二つの設定があり、ひとつは、System.out (TRACE_LEVEL_SYSTEM_OUT) トレーシングで、もうひとつはファイルトレーシング(TRACE_LEVEL_FILE)です。トレースレベルは、0 が OFF、1 が ERROR (デフォルト)、2 が INFO で 3 が DEBUGです。両方のレベルがDEBUGに設定されたデータベースURLです: トレースオプションを可能にする簡単な方法は、データベースURLにトレースオプションを設定することです。二つの設定があり、ひとつは、System.out (TRACE_LEVEL_SYSTEM_OUT) トレーシングで、もうひとつはファイルトレーシング(TRACE_LEVEL_FILE)です。トレースレベルは、0 が OFF、1 が ERROR (デフォルト)、2 が INFO で 3 が DEBUGです。両方のレベルがDEBUGに設定されたデータベースURLです:
@features_1533_p @features_1537_p
トレースレベルは、SQLコマンド <CODE>SET TRACE_LEVEL_SYSTEM_OUT level</CODE> (System.out トレーシング) または <CODE>SET TRACE_LEVEL_FILE level</CODE> (ファイルトレーシング) を実行することによってランタイムで変更できます。例: トレースレベルは、SQLコマンド <CODE>SET TRACE_LEVEL_SYSTEM_OUT level</CODE> (System.out トレーシング) または <CODE>SET TRACE_LEVEL_FILE level</CODE> (ファイルトレーシング) を実行することによってランタイムで変更できます。例:
@features_1534_h3 @features_1538_h3
トレースファイルの最大サイズを設定 トレースファイルの最大サイズを設定
@features_1535_p @features_1539_p
高いトレースレベルを使用する時、トレースファイルは早くサイズが非常に大きくなります。SQLステートメント <CODE>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</CODE> を実行することによりファイルのサイズを制限することができます。ログファイルが制限を超えたら、ファイルは ".old" にファイル名を変えて、新しいファイルが作成されます。もしもうひとつの .oldファイルが存在する場合は、それは削除されます。デフォルトの設定は16 MBです。例: 高いトレースレベルを使用する時、トレースファイルは早くサイズが非常に大きくなります。SQLステートメント <CODE>SET TRACE_MAX_FILE_SIZE maximumFileSizeInMB</CODE> を実行することによりファイルのサイズを制限することができます。ログファイルが制限を超えたら、ファイルは ".old" にファイル名を変えて、新しいファイルが作成されます。もしもうひとつの .oldファイルが存在する場合は、それは削除されます。デフォルトの設定は16 MBです。例:
@features_1536_h3 @features_1540_h3
Javaコード生成 Javaコード生成
@features_1537_p @features_1541_p
トレースレベルをINFOかDEBUGに設定した時、同様にJavaのソースコードが生成されるので、問題はより簡単に再生されます。トレースファイルはこのようなものです: トレースレベルをINFOかDEBUGに設定した時、同様にJavaのソースコードが生成されるので、問題はより簡単に再生されます。トレースファイルはこのようなものです:
@features_1538_p @features_1542_p
Javaのソースコードを得るために、 /**/ のない行を取り除く必要があります。 Windowsでの簡単な方法は: Javaのソースコードを得るために、 /**/ のない行を取り除く必要があります。 Windowsでの簡単な方法は:
@features_1539_p @features_1543_p
その後、コンパイルされる前にTrace.javaファイルを完全にする必要があります。例: その後、コンパイルされる前にTrace.javaファイルを完全にする必要があります。例:
@features_1540_p @features_1544_p
また、トレースファイルに載せられていないため、ユーザー名とパスワードが設定されている必要があります。 また、トレースファイルに載せられていないため、ユーザー名とパスワードが設定されている必要があります。
@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. #データベースファイルが読み取り専用なら、同様にデータベースも読み取り専用です。このデータベースで新しいテーブルを作成したり、データを追加したり変更したりすることはできません。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 &lt;database&gt;.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 &lt;database&gt;.trace.db for error messages.
@features_1547_h2 @features_1551_h2
読み取り専用データベース 読み取り専用データベース
@features_1548_p @features_1552_p
データベースファイルが読み取り専用なら、同様にデータベースも読み取り専用です。このデータベースで新しいテーブルを作成したり、データを追加したり変更したりすることはできません。SELECTステートメントのみ許可されています。読み取り専用データベースを作成するには、データベースを終了してログファイルを小さくします。ログファイルを削除してはいけません。そして、オペレーティングシステムを使用してデータベースファイルを読み取り専用にします。これでデータベースを開くと、読み取り専用になっています。アプリケーションが、データベースが読み取り専用であることを判断する方法は二つあります: Connection.isReadOnly() を呼ぶか、SQLステートメント CALL READONLY() を実行します。 データベースファイルが読み取り専用なら、同様にデータベースも読み取り専用です。このデータベースで新しいテーブルを作成したり、データを追加したり変更したりすることはできません。SELECTステートメントのみ許可されています。読み取り専用データベースを作成するには、データベースを終了してログファイルを小さくします。ログファイルを削除してはいけません。そして、オペレーティングシステムを使用してデータベースファイルを読み取り専用にします。これでデータベースを開くと、読み取り専用になっています。アプリケーションが、データベースが読み取り専用であることを判断する方法は二つあります: Connection.isReadOnly() を呼ぶか、SQLステートメント 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. #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スクリプト) が破損しているため、データベースを開くことができない場合、データベースイベントリスナーを指定することでデータベースを開くことができます。例外は記録されますが、データベースの開始は続行します。
@features_1557_h2 @features_1561_h2
computed column / ベースインデックスの機能 computed column / ベースインデックスの機能
@features_1558_p @features_1562_p
インデックスの機能は、このデータベースによって直接サポートはされていませんが、computed columnsを使用することによって、簡単にエミュレートすることができます。例えば、カラムのupper-caseバージョンのインデックスが必要なら、原形のカラムのupper-caseバージョンのcomputed columnを作成し、このカラムにインデックスをつけます: インデックスの機能は、このデータベースによって直接サポートはされていませんが、computed columnsを使用することによって、簡単にエミュレートすることができます。例えば、カラムのupper-caseバージョンのインデックスが必要なら、原形のカラムのupper-caseバージョンのcomputed columnを作成し、このカラムにインデックスをつけます:
@features_1559_p @features_1563_p
値は生成されているので、データを挿入する時、カラムのupper-caseバージョンのための値を指定する必要はありません (許可されていません)。 しかし、テーブルを呼ぶ時、このカラムを使用することはできます。: 値は生成されているので、データを挿入する時、カラムのupper-caseバージョンのための値を指定する必要はありません (許可されていません)。 しかし、テーブルを呼ぶ時、このカラムを使用することはできます。:
@features_1560_h2 @features_1564_h2
多次元インデックス 多次元インデックス
@features_1561_p @features_1565_p
効率的な多次元の (空間的) 領域のクエリーを実行するためにツールを提供します。このデータベースは専門的な空間的インデックス (R-Tree またはより小さいもの) をサポートしていません。代わりに、B-Treeインデックスが使われています。それぞれのレコードに対して、多次元のキーは、単数範囲 (スカラー) の値に変換 (位置づけ) されます。この値は、space-filling curve (空間充填曲線) で位置を指定します。 効率的な多次元の (空間的) 領域のクエリーを実行するためにツールを提供します。このデータベースは専門的な空間的インデックス (R-Tree またはより小さいもの) をサポートしていません。代わりに、B-Treeインデックスが使われています。それぞれのレコードに対して、多次元のキーは、単数範囲 (スカラー) の値に変換 (位置づけ) されます。この値は、space-filling curve (空間充填曲線) で位置を指定します。
@features_1562_p @features_1566_p
現在、Z-order (N-order または Morton-order とも呼ばれています) が使用されています; Hilbert curveも使用できますが、実装はより複雑です。多次元の値を変換するアルゴリズムは、bit-interleavingと呼ばれています。B-Treeインデックス (通常は computed columnを使用します)を使用することで、スカラーの値はインデックスをつけられます。 現在、Z-order (N-order または Morton-order とも呼ばれています) が使用されています; Hilbert curveも使用できますが、実装はより複雑です。多次元の値を変換するアルゴリズムは、bit-interleavingと呼ばれています。B-Treeインデックス (通常は computed columnを使用します)を使用することで、スカラーの値はインデックスをつけられます。
@features_1563_p @features_1567_p
最初のカラムにインデックスを使用する上で、メソッドは徹底的なパフォーマンスの改良をもたらすことができます。データと次元の数によりますが、改良は通常、factor 5よりも高いものです。指定された多次元の範囲から、ツールはSQLクエリーを生成します。使用されたメソッドは、データベースに依存しておらず、ツールは簡単に他のデータベースに移植することができます。ツールの使用方法の例は、TestMultiDimension.java で提供されているサンプルコードをご覧下さい。 最初のカラムにインデックスを使用する上で、メソッドは徹底的なパフォーマンスの改良をもたらすことができます。データと次元の数によりますが、改良は通常、factor 5よりも高いものです。指定された多次元の範囲から、ツールはSQLクエリーを生成します。使用されたメソッドは、データベースに依存しておらず、ツールは簡単に他のデータベースに移植することができます。ツールの使用方法の例は、TestMultiDimension.java で提供されているサンプルコードをご覧下さい。
@features_1564_h2 @features_1568_h2
パスワードを使用する パスワードを使用する
@features_1565_h3 @features_1569_h3
安全なパスワードを使用する 安全なパスワードを使用する
@features_1566_p @features_1570_p
弱いパスワードは、暗号化やセキュリティプロトコルに取るに足らず、解読されてしまうことを覚えておいて下さい。辞書で見つけられるようなパスワードは使用しないでください。また、数字を付け足してもそのようなパスワードは安全にはなりません。良いパスワードを作る方法は、覚えやすい、文章の最初の文字を使う、大文字と小文字を使う、特別な文字が含まれているものを作る、です。例: 弱いパスワードは、暗号化やセキュリティプロトコルに取るに足らず、解読されてしまうことを覚えておいて下さい。辞書で見つけられるようなパスワードは使用しないでください。また、数字を付け足してもそのようなパスワードは安全にはなりません。良いパスワードを作る方法は、覚えやすい、文章の最初の文字を使う、大文字と小文字を使う、特別な文字が含まれているものを作る、です。例:
@features_1567_p @features_1571_p
i'sE2rtPiUKtT (もしトリックを知っていれば、このパスワードは覚えやすいものです) i'sE2rtPiUKtT (もしトリックを知っていれば、このパスワードは覚えやすいものです)
@features_1568_h3 @features_1572_h3
パスワード: Stringの代わりにChar Arraysを使用する パスワード: Stringの代わりにChar Arraysを使用する
@features_1569_p @features_1573_p
Java Stringは不変のオブジェクトであり、アプリケーションによって安全に壊されることはできません。Stringの作成後、Stringは少なくともガベージコレクションになるまで、コンピューターのメインメモリ内にとどまるでしょう。ガベージコレクションはアプリケーションによって制御されず、ガベージコレクションであっても、データはまだメモリにとどまっているでしょう。パスワードが含まれるメモリの一部をディスクと取り換えることも可能でしょう (十分でないメインメモリも使用可能のため)。 Java Stringは不変のオブジェクトであり、アプリケーションによって安全に壊されることはできません。Stringの作成後、Stringは少なくともガベージコレクションになるまで、コンピューターのメインメモリ内にとどまるでしょう。ガベージコレクションはアプリケーションによって制御されず、ガベージコレクションであっても、データはまだメモリにとどまっているでしょう。パスワードが含まれるメモリの一部をディスクと取り換えることも可能でしょう (十分でないメインメモリも使用可能のため)。
@features_1570_p @features_1574_p
アタッカーはオペレーティングシステムのスワップファイルにアクセスするでしょう。したがって、パスワードを保存するために、Stringの代わりにchar arrayを使用するのは良い方法です。char arrayは使用後クリアにされるので (0で埋められます)、パスワードはスワップファイルに保存されません。 アタッカーはオペレーティングシステムのスワップファイルにアクセスするでしょう。したがって、パスワードを保存するために、Stringの代わりにchar arrayを使用するのは良い方法です。char arrayは使用後クリアにされるので (0で埋められます)、パスワードはスワップファイルに保存されません。
@features_1571_p @features_1575_p
このデータベースは、ユーザーパスワードとファイルパスワードを認証するために、Stringの代わりにchar arrayを使用することをサポートしています。次のコードはこのように使用されます: このデータベースは、ユーザーパスワードとファイルパスワードを認証するために、Stringの代わりにchar arrayを使用することをサポートしています。次のコードはこのように使用されます:
@features_1572_p @features_1576_p
このサンプルでは、パスワードはアプリケーションでのハードコードで、もちろん安全ではありません。しかし、Java Swingはchar arrayを使用してパスワードを得る方法をサポートしています (JPasswordField)。 このサンプルでは、パスワードはアプリケーションでのハードコードで、もちろん安全ではありません。しかし、Java Swingはchar arrayを使用してパスワードを得る方法をサポートしています (JPasswordField)。
@features_1573_h3 @features_1577_h3
ユーザー名 と (または) パスワードをURLで認証する ユーザー名 と (または) パスワードを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. #完全なサンプルアプリケーションは 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_1577_p @features_1581_p
Java関数は、CREATE ALIAS と呼ばれるデータベースに登録されていなければなりません: Java関数は、CREATE ALIAS と呼ばれるデータベースに登録されていなければなりません:
@features_1578_p @features_1582_p
完全なサンプルアプリケーションは src/test/org/h2/samples/Function.java をご覧下さい。 完全なサンプルアプリケーションは src/test/org/h2/samples/Function.java をご覧下さい。
@features_1579_h3 @features_1583_h3
データタイプマッピング関数 データタイプマッピング関数
@features_1580_p @features_1584_p
"int" のような non-nullable (NULL可能ではない) パラメータを受け入れる関数は、パラメータのうちひとつがNULLであるなら呼ばれないでしょう。このケースでは、NULLの値は結果として使用されます。このケースで関数を呼び出したいのなら、"int" の代わりに "java.lang.Integer" を使用する必要があります。 "int" のような non-nullable (NULL可能ではない) パラメータを受け入れる関数は、パラメータのうちひとつがNULLであるなら呼ばれないでしょう。このケースでは、NULLの値は結果として使用されます。このケースで関数を呼び出したいのなら、"int" の代わりに "java.lang.Integer" を使用する必要があります。
@features_1581_h3 @features_1585_h3
接続を必要とする関数 接続を必要とする関数
@features_1582_p @features_1586_p
もしJava関数の最初のパラメータが java.sql.Connection なら、データベースへの接続は与えられています。返す前にこの接続を閉じる必要はありません。 もしJava関数の最初のパラメータが java.sql.Connection なら、データベースへの接続は与えられています。返す前にこの接続を閉じる必要はありません。
@features_1583_h3 @features_1587_h3
例外を投げる関数 例外を投げる関数
@features_1584_p @features_1588_p
関数が例外を投げたら、現在のステートメントはロールバックされ、例外はアプリケーションに投げられます。 関数が例外を投げたら、現在のステートメントはロールバックされ、例外はアプリケーションに投げられます。
@features_1585_h3 @features_1589_h3
Result Setを返す関数 Result Setを返す関数
@features_1586_p @features_1590_p
関数はresult setを返します。このような関数はCALLステートメントと一緒に呼ばれます: 関数はresult setを返します。このような関数はCALLステートメントと一緒に呼ばれます:
@features_1587_h3 @features_1591_h3
SimpleResultSetを使用する SimpleResultSetを使用する
@features_1588_p @features_1592_p
result setを返す関数は、SimpleResultSetツールを使用して最初からこのresult setを作成することができます: result setを返す関数は、SimpleResultSetツールを使用して最初からこのresult setを作成することができます:
@features_1589_h3 @features_1593_h3
関数をテーブルとして使用する 関数をテーブルとして使用する
@features_1590_p @features_1594_p
result setを返す関数はテーブルのようになれます。しかし、このケースでは関数は少なくとも二回は呼ばれます: 最初はカラム名を集めるために構文解析している間です (コンパイル時に未知のところでパラメータはNULLに設定)。そして、データを取得するためにステートメントを実行している間です (これが結合なら繰り返されます)。関数がカラム一覧を取得するためだけに呼ばれたのなら、関数を認証する接続URLは jdbc:columnlist:connection です。そうでなければ、接続URLは jdbc:default:connection です。 result setを返す関数はテーブルのようになれます。しかし、このケースでは関数は少なくとも二回は呼ばれます: 最初はカラム名を集めるために構文解析している間です (コンパイル時に未知のところでパラメータはNULLに設定)。そして、データを取得するためにステートメントを実行している間です (これが結合なら繰り返されます)。関数がカラム一覧を取得するためだけに呼ばれたのなら、関数を認証する接続URLは jdbc:columnlist:connection です。そうでなければ、接続URLは jdbc:default:connection です。
@features_1591_h2 @features_1595_h2
トリガー トリガー
@features_1592_p @features_1596_p
このデータベースは、行が更新、挿入、または削除された前後に呼ばれるJavaトリガーをサポートしています。トリガーは複雑な一貫性チェックか、データベース内の関連したデータをアップデートするのに使用されます。マテリアライズドビューをシミュレートするためにトリガーを使用することも可能です。完全なサンプルアプリケーションは src/test/org/h2/samples/TriggerSample.java をご覧下さい。Javaトリガーは、インターフェイス org.h2.api.Trigger を実装しなければなりません: このデータベースは、行が更新、挿入、または削除された前後に呼ばれるJavaトリガーをサポートしています。トリガーは複雑な一貫性チェックか、データベース内の関連したデータをアップデートするのに使用されます。マテリアライズドビューをシミュレートするためにトリガーを使用することも可能です。完全なサンプルアプリケーションは src/test/org/h2/samples/TriggerSample.java をご覧下さい。Javaトリガーは、インターフェイス org.h2.api.Trigger を実装しなければなりません:
@features_1593_p @features_1597_p
他のテーブルのクエリーかデータのアップデートに接続を使用することができます。トリガーはその時データベースで定義されている必要があります: 他のテーブルのクエリーかデータのアップデートに接続を使用することができます。トリガーはその時データベースで定義されている必要があります:
@features_1594_p @features_1598_p
トリガーはSQL Exceptionを投げることによって、変更を禁止させることができます。 トリガーはSQL Exceptionを投げることによって、変更を禁止させることができます。
@features_1595_h2 @features_1599_h2
データベースをコンパクトにする データベースをコンパクトにする
@features_1596_p @features_1600_p
データベースファイルの空のスペースは自動的に再利用されます。インデックスを再構築するもっとも簡単な方法は、データベースが閉じられている間に .index.db ファイルを削除します。しかし、一部状況では (例えば、データベースの多数のデータを削除した後)、データベースのサイズを縮小したい場合があります (データベースをコンパクトにする)。そのためのサンプルです: データベースファイルの空のスペースは自動的に再利用されます。インデックスを再構築するもっとも簡単な方法は、データベースが閉じられている間に .index.db ファイルを削除します。しかし、一部状況では (例えば、データベースの多数のデータを削除した後)、データベースのサイズを縮小したい場合があります (データベースをコンパクトにする)。そのためのサンプルです:
@features_1597_p @features_1601_p
サンプルアプリケーション org.h2.samples.Compact もご覧下さい。データベースのバックアップを作るのと、スクリプトからデータベースを再構築するのにSCRIPT / RUNSCRIPT コマンドを使用することができます。 サンプルアプリケーション org.h2.samples.Compact もご覧下さい。データベースのバックアップを作るのと、スクリプトからデータベースを再構築するのにSCRIPT / RUNSCRIPT コマンドを使用することができます。
@features_1598_h2 @features_1602_h2
キャッシュの設定 キャッシュの設定
@features_1599_p @features_1603_p
データベースは最も頻繁に使われるデータやインデックスページをメインメモリに保存します。キャッシュに使用されるメモリ量を CACHE_SIZE 設定を使用して変更することができます。この設定は、データベース接続URL (jdbc:h2:~/test;CACHE_SIZE=131072) か、ランタイムにSET CACHE_SIZE を使用してサイズを変更できます。 データベースは最も頻繁に使われるデータやインデックスページをメインメモリに保存します。キャッシュに使用されるメモリ量を CACHE_SIZE 設定を使用して変更することができます。この設定は、データベース接続URL (jdbc:h2:~/test;CACHE_SIZE=131072) か、ランタイムにSET CACHE_SIZE を使用してサイズを変更できます。
@features_1600_p @features_1604_p
このデータベースは二つのcache page replacement algorithms (キャッシュページ置換アルゴリズム) をサポートしています: LRU (デフォルト) と2Qです。LRUは、キャッシュがいっぱいになったら、頻繁に使用されていないページをキャッシュから削除します。2Qアルゴリズムは少し複雑で、基本的に二つのクエリーが使用されます。2Qアルゴリズムはテーブルスキャンに、より抵抗がありますが、LRUと比較してオーバーヘッドは少し高めです。キャッシュアルゴリズム 2Qを使用するためには、フォームのデータベースURL jdbc:h2:~/test;CACHE_TYPE=TQ を使用します。キャッシュアルゴリズムは、一度データベースが開かれたら変更することはできません。 このデータベースは二つのcache page replacement algorithms (キャッシュページ置換アルゴリズム) をサポートしています: LRU (デフォルト) と2Qです。LRUは、キャッシュがいっぱいになったら、頻繁に使用されていないページをキャッシュから削除します。2Qアルゴリズムは少し複雑で、基本的に二つのクエリーが使用されます。2Qアルゴリズムはテーブルスキャンに、より抵抗がありますが、LRUと比較してオーバーヘッドは少し高めです。キャッシュアルゴリズム 2Qを使用するためには、フォームのデータベースURL jdbc:h2:~/test;CACHE_TYPE=TQ を使用します。キャッシュアルゴリズムは、一度データベースが開かれたら変更することはできません。
@features_1601_p @features_1605_p
読んだり書いたりしたページや、現在使用されているキャッシュアルゴリズムの情報を得るためには、SELECT * FROM INFORMATION_SCHEMA.SETTINGS を呼びます。データとインデックスファイルに読み書きしたページ数が書かれています。 読んだり書いたりしたページや、現在使用されているキャッシュアルゴリズムの情報を得るためには、SELECT * FROM INFORMATION_SCHEMA.SETTINGS を呼びます。データとインデックスファイルに読み書きしたページ数が書かれています。
@fragments_1000_b @fragments_1000_b
......
...@@ -906,7 +906,7 @@ features_1034_a=Cache Settings ...@@ -906,7 +906,7 @@ features_1034_a=Cache Settings
features_1035_h2=Feature List features_1035_h2=Feature List
features_1036_h3=Main Features features_1036_h3=Main Features
features_1037_li=Very fast database engine features_1037_li=Very fast database engine
features_1038_li=Free, with source code features_1038_li=Open source
features_1039_li=Written in Java features_1039_li=Written in Java
features_1040_li=Supports standard SQL, JDBC API features_1040_li=Supports standard SQL, JDBC API
features_1041_li=Embedded and Server mode, Clustering support features_1041_li=Embedded and Server mode, Clustering support
...@@ -947,9 +947,9 @@ features_1075_li=CSV (comma separated values) file support ...@@ -947,9 +947,9 @@ features_1075_li=CSV (comma separated values) file support
features_1076_li=Support for linked tables, and a built-in virtual 'range' table features_1076_li=Support for linked tables, and a built-in virtual 'range' table
features_1077_li=EXPLAIN PLAN support, sophisticated trace options features_1077_li=EXPLAIN PLAN support, sophisticated trace options
features_1078_li=Database closing can be delayed or disabled to improve the performance features_1078_li=Database closing can be delayed or disabled to improve the performance
features_1079_li=Web-based Console application (English, German, partially French and Spanish) with autocomplete features_1079_li=Web-based Console application (translated to many languages) with autocomplete
features_1080_li=The database can generate SQL script files features_1080_li=The database can generate SQL script files
features_1081_li=Contains a recovery tool that can dump the contents of the data file features_1081_li=Contains a recovery tool that can dump the contents of the database
features_1082_li=Support for variables (for example to calculate running totals) features_1082_li=Support for variables (for example to calculate running totals)
features_1083_li=Automatic re-compilation of prepared statements features_1083_li=Automatic re-compilation of prepared statements
features_1084_li=Uses a small number of database files features_1084_li=Uses a small number of database files
...@@ -1133,343 +1133,347 @@ features_1261_p=*4 Derby only supports global temporary tables. ...@@ -1133,343 +1133,347 @@ features_1261_p=*4 Derby only supports global temporary tables.
features_1262_p=*5 The default H2 jar file contains debug information, jar files for other databases do not. features_1262_p=*5 The default H2 jar file contains debug information, jar files for other databases do not.
features_1263_p=*6 PostgreSQL supports functional indexes. features_1263_p=*6 PostgreSQL supports functional indexes.
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_1289_a=Embedded (local) connection features_1289_th=Topic
features_1290_td=jdbc\:h2\:[file\:][&lt;path&gt;]&lt;databaseName&gt; features_1290_th=URL Format and Examples
features_1291_td=jdbc\:h2\:~/test features_1291_a=Embedded (local) connection
features_1292_td=jdbc\:h2\:file\:/data/sample features_1292_td=jdbc\:h2\:[file\:][&lt;path&gt;]&lt;databaseName&gt;
features_1293_td=jdbc\:h2\:file\:C\:/data/sample (Windows only) features_1293_td=jdbc\:h2\:~/test
features_1294_a=In-Memory (private) features_1294_td=jdbc\:h2\:file\:/data/sample
features_1295_td=jdbc\:h2\:mem\: features_1295_td=jdbc\:h2\:file\:C\:/data/sample (Windows only)
features_1296_a=In-Memory (named) features_1296_a=In-memory (private)
features_1297_td=jdbc\:h2\:mem\:&lt;databaseName&gt; features_1297_td=jdbc\:h2\:mem\:
features_1298_td=jdbc\:h2\:mem\:test_mem features_1298_a=In-memory (named)
features_1299_a=Remote using TCP/IP features_1299_td=jdbc\:h2\:mem\:&lt;databaseName&gt;
features_1300_td=jdbc\:h2\:tcp\://&lt;server&gt;[\:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt; features_1300_td=jdbc\:h2\:mem\:test_mem
features_1301_td=jdbc\:h2\:tcp\://localhost/~/test features_1301_a=Server mode (remote connections)
features_1302_td=jdbc\:h2\:tcp\://dbserv\:8084/~/sample features_1302_a=using TCP/IP
features_1303_a=Remote using SSL/TLS features_1303_td=jdbc\:h2\:tcp\://&lt;server&gt;[\:&lt;port&gt;]/[&lt;path&gt;]&lt;databaseName&gt;
features_1304_td=jdbc\:h2\:ssl\://&lt;server&gt;[\:&lt;port&gt;]/&lt;databaseName&gt; features_1304_td=jdbc\:h2\:tcp\://localhost/~/test
features_1305_td=jdbc\:h2\:ssl\://secureserv\:8085/~/sample; features_1305_td=jdbc\:h2\:tcp\://dbserv\:8084/~/sample
features_1306_a=Using Encrypted Files features_1306_a=Server mode (remote connections)
features_1307_td=jdbc\:h2\:&lt;url&gt;;CIPHER\=[AES|XTEA] features_1307_a=using SSL/TLS
features_1308_td=jdbc\:h2\:ssl\://secureserv/~/testdb;CIPHER\=AES features_1308_td=jdbc\:h2\:ssl\://&lt;server&gt;[\:&lt;port&gt;]/&lt;databaseName&gt;
features_1309_td=jdbc\:h2\:file\:~/secure;CIPHER\=XTEA features_1309_td=jdbc\:h2\:ssl\://secureserv\:8085/~/sample;
features_1310_a=File Locking Methods features_1310_a=Using encrypted files
features_1311_td=jdbc\:h2\:&lt;url&gt;;FILE_LOCK\={NO|FILE|SOCKET} features_1311_td=jdbc\:h2\:&lt;url&gt;;CIPHER\=[AES|XTEA]
features_1312_td=jdbc\:h2\:file\:~/quickAndDirty;FILE_LOCK\=NO features_1312_td=jdbc\:h2\:ssl\://secureserv/~/testdb;CIPHER\=AES
features_1313_td=jdbc\:h2\:file\:~/private;CIPHER\=XTEA;FILE_LOCK\=SOCKET features_1313_td=jdbc\:h2\:file\:~/secure;CIPHER\=XTEA
features_1314_a=Only Open if it Already Exists features_1314_a=File locking methods
features_1315_td=jdbc\:h2\:&lt;url&gt;;IFEXISTS\=TRUE features_1315_td=jdbc\:h2\:&lt;url&gt;;FILE_LOCK\={NO|FILE|SOCKET}
features_1316_td=jdbc\:h2\:file\:~/sample;IFEXISTS\=TRUE features_1316_td=jdbc\:h2\:file\:~/quickAndDirty;FILE_LOCK\=NO
features_1317_a=Don't Close the Database when the VM Exits features_1317_td=jdbc\:h2\:file\:~/private;CIPHER\=XTEA;FILE_LOCK\=SOCKET
features_1318_td=jdbc\:h2\:&lt;url&gt;;DB_CLOSE_ON_EXIT\=FALSE features_1318_a=Only open if it already exists
features_1319_a=User Name and/or Password features_1319_td=jdbc\:h2\:&lt;url&gt;;IFEXISTS\=TRUE
features_1320_td=jdbc\:h2\:&lt;url&gt;[;USER\=&lt;username&gt;][;PASSWORD\=&lt;value&gt;] features_1320_td=jdbc\:h2\:file\:~/sample;IFEXISTS\=TRUE
features_1321_td=jdbc\:h2\:file\:~/sample;USER\=sa;PASSWORD\=123 features_1321_a=Don't close the database when the VM exits
features_1322_a=Log Index Changes features_1322_td=jdbc\:h2\:&lt;url&gt;;DB_CLOSE_ON_EXIT\=FALSE
features_1323_td=jdbc\:h2\:&lt;url&gt;;LOG\=2 features_1323_a=User name and/or password
features_1324_td=jdbc\:h2\:file\:~/sample;LOG\=2 features_1324_td=jdbc\:h2\:&lt;url&gt;[;USER\=&lt;username&gt;][;PASSWORD\=&lt;value&gt;]
features_1325_a=Debug Trace Settings features_1325_td=jdbc\:h2\:file\:~/sample;USER\=sa;PASSWORD\=123
features_1326_td=jdbc\:h2\:&lt;url&gt;;TRACE_LEVEL_FILE\=&lt;level 0..3&gt; features_1326_a=Log index changes
features_1327_td=jdbc\:h2\:file\:~/sample;TRACE_LEVEL_FILE\=3 features_1327_td=jdbc\:h2\:&lt;url&gt;;LOG\=2
features_1328_a=Ignore Unknown Settings features_1328_td=jdbc\:h2\:file\:~/sample;LOG\=2
features_1329_td=jdbc\:h2\:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS\=TRUE features_1329_a=Debug trace settings
features_1330_a=Custom File Access Mode features_1330_td=jdbc\:h2\:&lt;url&gt;;TRACE_LEVEL_FILE\=&lt;level 0..3&gt;
features_1331_td=jdbc\:h2\:&lt;url&gt;;ACCESS_MODE_LOG\=rws;ACCESS_MODE_DATA\=rws features_1331_td=jdbc\:h2\:file\:~/sample;TRACE_LEVEL_FILE\=3
features_1332_a=Database in or Zip File features_1332_a=Ignore unknown settings
features_1333_td=jdbc\:h2\:zip\:&lt;zipFileName&gt;\!/&lt;databaseName&gt; features_1333_td=jdbc\:h2\:&lt;url&gt;;IGNORE_UNKNOWN_SETTINGS\=TRUE
features_1334_td=jdbc\:h2\:zip\:~/db.zip\!/test features_1334_a=Custom file access mode
features_1335_a=Compatibility Mode features_1335_td=jdbc\:h2\:&lt;url&gt;;ACCESS_MODE_LOG\=rws;ACCESS_MODE_DATA\=rws
features_1336_td=jdbc\:h2\:&lt;url&gt;;MODE\=&lt;databaseType&gt; features_1336_a=Database in a zip file
features_1337_td=jdbc\:h2\:~/test;MODE\=MYSQL features_1337_td=jdbc\:h2\:zip\:&lt;zipFileName&gt;\!/&lt;databaseName&gt;
features_1338_a=Auto-Reconnect features_1338_td=jdbc\:h2\:zip\:~/db.zip\!/test
features_1339_td=jdbc\:h2\:&lt;url&gt;;AUTO_RECONNECT\=TRUE features_1339_a=Compatibility mode
features_1340_td=jdbc\:h2\:tcp\://localhost/~/test;AUTO_RECONNECT\=TRUE features_1340_td=jdbc\:h2\:&lt;url&gt;;MODE\=&lt;databaseType&gt;
features_1341_a=Automatic Mixed Mode features_1341_td=jdbc\:h2\:~/test;MODE\=MYSQL
features_1342_td=jdbc\:h2\:&lt;url&gt;;AUTO_SERVER\=TRUE features_1342_a=Auto-reconnect
features_1343_td=jdbc\:h2\:~/test;AUTO_SERVER\=TRUE features_1343_td=jdbc\:h2\:&lt;url&gt;;AUTO_RECONNECT\=TRUE
features_1344_a=Changing Other Settings features_1344_td=jdbc\:h2\:tcp\://localhost/~/test;AUTO_RECONNECT\=TRUE
features_1345_td=jdbc\:h2\:&lt;url&gt;;&lt;setting&gt;\=&lt;value&gt;[;&lt;setting&gt;\=&lt;value&gt;...] features_1345_a=Automatic mixed mode
features_1346_td=jdbc\:h2\:file\:~/sample;TRACE_LEVEL_SYSTEM_OUT\=3 features_1346_td=jdbc\:h2\:&lt;url&gt;;AUTO_SERVER\=TRUE
features_1347_h2=Connecting to an Embedded (Local) Database features_1347_td=jdbc\:h2\:~/test;AUTO_SERVER\=TRUE
features_1348_p=The database URL for connecting to a local database is <code>jdbc\:h2\:[file\:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file\:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of File.createTempFile). To point to the user home directory, use ~/, as in\: jdbc\:h2\:~/test. features_1348_a=Changing other settings
features_1349_h2=Memory-Only Databases features_1349_td=jdbc\:h2\:&lt;url&gt;;&lt;setting&gt;\=&lt;value&gt;[;&lt;setting&gt;\=&lt;value&gt;...]
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_1350_td=jdbc\:h2\:file\:~/sample;TRACE_LEVEL_SYSTEM_OUT\=3
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\:][&lt;path&gt;]&lt;databaseName&gt;</code> . The prefix <code>file\:</code> is optional. If no or only a relative path is used, then the current working directory is used as a starting point. The case sensitivity of the path and database name depend on the operating system, however it is recommended to use lowercase letters only. The database name must be at least three characters long (a limitation of 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 &lt;seconds&gt;. 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 &lt;seconds&gt;. 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 &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent. features_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 &lt;milliseconds&gt;. The initial lock timeout (that is the timeout used for new connections) can be set using the SQL command SET DEFAULT_LOCK_TIMEOUT &lt;milliseconds&gt;. The default lock timeout is persistent.
features_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\: &lt;database&gt;.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_1429_td=Format\: &lt;database&gt;.data.db
features_1430_td=Format\: &lt;database&gt;.index.db features_1430_td=1 per database
features_1431_td=1 per database features_1431_td=test.index.db
features_1432_td=test.0.log.db features_1432_td=Index file
features_1433_td=Log file features_1433_td=Contains the data for all (btree) indexes
features_1434_td=The log file is used for recovery features_1434_td=Format\: &lt;database&gt;.index.db
features_1435_td=Format\: &lt;database&gt;.&lt;id&gt;.log.db features_1435_td=1 per database
features_1436_td=0 or more per database features_1436_td=test.0.log.db
features_1437_td=test.lock.db features_1437_td=Log file
features_1438_td=Database lock file features_1438_td=The log file is used for recovery
features_1439_td=Exists only if the database is open features_1439_td=Format\: &lt;database&gt;.&lt;id&gt;.log.db
features_1440_td=Format\: &lt;database&gt;.lock.db features_1440_td=0 or more per database
features_1441_td=1 per database features_1441_td=test.lock.db
features_1442_td=test.trace.db features_1442_td=Database lock file
features_1443_td=Trace file features_1443_td=Exists only if the database is open
features_1444_td=Contains trace information features_1444_td=Format\: &lt;database&gt;.lock.db
features_1445_td=Format\: &lt;database&gt;.trace.db features_1445_td=1 per database
features_1446_td=If the file is too big, it is renamed to &lt;database&gt;.trace.db.old features_1446_td=test.trace.db
features_1447_td=1 per database features_1447_td=Trace file
features_1448_td=test.14.15.lob.db features_1448_td=Contains trace information
features_1449_td=Large object features_1449_td=Format\: &lt;database&gt;.trace.db
features_1450_td=Contains the data for BLOB or CLOB features_1450_td=If the file is too big, it is renamed to &lt;database&gt;.trace.db.old
features_1451_td=Format\: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db features_1451_td=1 per database
features_1452_td=1 per object features_1452_td=test.14.15.lob.db
features_1453_td=test.123.temp.db features_1453_td=Large object
features_1454_td=Temporary file features_1454_td=Contains the data for BLOB or CLOB
features_1455_td=Contains a temporary blob or a large result set features_1455_td=Format\: &lt;database&gt;.&lt;tableid&gt;.&lt;id&gt;.lob.db
features_1456_td=Format\: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db features_1456_td=1 per object
features_1457_td=1 per object features_1457_td=test.123.temp.db
features_1458_td=test.7.hash.db features_1458_td=Temporary file
features_1459_td=Hash index file features_1459_td=Contains a temporary blob or a large result set
features_1460_td=Contains the data for a linear hash index features_1460_td=Format\: &lt;database&gt;.&lt;session id&gt;.&lt;object id&gt;.temp.db
features_1461_td=Format\: &lt;database&gt;.&lt;object id&gt;.hash.db features_1461_td=1 per object
features_1462_td=1 per linear hash index features_1462_td=test.7.hash.db
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_1465_td=Format\: &lt;database&gt;.&lt;object id&gt;.hash.db
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 &lt;database&gt;.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 &lt;database&gt;.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.
fragments_1000_b=Search\: fragments_1000_b=Search\:
fragments_1001_td=Highlight keyword(s) fragments_1001_td=Highlight keyword(s)
fragments_1002_a=Home fragments_1002_a=Home
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论