Page History
...
console
- Invokes the H2 Console for use with a browser.
- Users can specify the
--web-port
option and otherwise use default port8082
.
shell
- Invokes the H2 Shell for execution of SQL statements:
- SQL statements can be specified using the
--sql
option. - Using the
--file
option a file can be specified holding SQL statements. - Without the
--sql
and--file
options the interactive H2 Shell can will be used.
- SQL statements can be specified using the
- Invokes the H2 Shell for execution of SQL statements:
- export
- Exports the database specified to a .zip compressed .archive file.
- The archive file includes the
script.sql
file holding SQL statements that can be used to recreate the database.
import
- Imports data from a previous backup. Backup files hold the full backup of the database. To restore a database it is recommended to (re)move the existing H2 database. The database will be recreated on import.
- The backup file created using the
export
command must be extracted to the resultingscript.sql
file. - The path to the
script.sql
file is specified with the--file
option.
...
--classpath
- H2 ships from a single Java binary file, for example
h2-2.3.232.jar
. - The option specifies the path to the H2 Java binary file.
- H2 ships from a single Java binary file, for example
--url
- Specifies the location of the H2 database. The JS7 - Database using H2 is located with JOC Cockpit from the
<jetty-base>/resources/joc/h2
directory. The name of the database isjoc
. - The URL is prefixed with
jdbc:h2:
followed by the relative or absolute path to the database. If the prefix is omitted, it will be added by the script. - Examples:
jdbc:h2:/var/sos-berlin.com/js7/joc/resources/joc/h2/joc
/var/sos-berlin.com/js7/joc/resources/joc/h2/joc
- Specifies the location of the H2 database. The JS7 - Database using H2 is located with JOC Cockpit from the
--driver
- Specifies the class name of the H2 JDBC Driver, default:
org.h2.Driver
.
- Specifies the class name of the H2 JDBC Driver, default:
--user
- Specifies the account for the H2 database, default:
joc
.
- Specifies the account for the H2 database, default:
--password
- Specifies the password used for the account specified with the
--user
option for the H2 database, default: no password. - Password input from the command line is considered insecure. Consider use of the
-p
switch offering a secure option for interactive keyboard input.
- Specifies the password used for the account specified with the
--file
- When used with the
export
command, specifies the path to the .zip archive file that holds the database backup. - When used with the
import
command, specifies the path to the .sql script file used to restore the database. - When used with the
shell
command, specifies the path to the .sql script file that holds SQL statements that should be executed.
- When used with the
--sql
- When used with the
shell
command specifies the SQL statement that should be executed. - Consider to apply quotes as in
--sql="SELECT COUNT(*) FROMM JOC_VARIABLES;"
. SQL statements should be terminated by semicolon.
- When used with the
--web-port
- When used with the
console
command specifies the port used by the H2 Console, default:8082
.
- When used with the
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# invoking the H2 consoleConsole for default port 8082 ./h2.sh console # invoking the H2 consoleConsole for the port specified using the Java binary from the current directory ./h2.sh console --web-port=8081 --classpath=./h2-2.3.232.jar |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# invoking the H2 shellShell using the Java binary from the current directory ./h2.sh shell --url="/home/sos/h2/joc" --classpath=./h2-2.3.232.jar |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# execute SQL statement from the command line
./h2.sh shell --url="/home/sos/h2/joc" --user=joc --sql="SELECT COUNT(*) FROMM JOC_VARIABLES;"
# execute SQL statement from file
./h2.sh shell --url="/home/sos/h2/joc" --user=joc --file=/tmp/run.sql |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# export database to .zip archive file that holds the script.sql file ./h2.sh export --url="/home/sos/h2/joc" --user=joc --file=/tmp/database.zip |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# # import to database # step 1: (re)move existing database mv /home/sos/h2 /home/sos/h2.backup # step 2: unzip .zip archive file to receive the script.sql file unzip /tmp/database.zip # step 3: perform import, the database is automatically created ./h2.sh import --url="/home/sos/h2/joc" --user=joc --file=/tmp/script.sql |
Overview
Content Tools