H2 database
作成されていないDBにアクセスできない
h2 1.4.200, windows
問題
Database "mem:dbname" not found, either pre-create it or allow remote database creation (not recommended in secure environments) というエラーが表示される
解決策1 > 失敗
タスクトレイアイコンをクリック https://gyazo.com/52604a4308e5bd338ac187a935da99cc
https://gyazo.com/9a324a7827a5856e3be9f54e0ba7e694 データベース作成画面から作成する
例 dbnameというin-memoryデータベースを作りたい場合は Database path を mem:dbname にする
解決策2
code:myh2.bat
@start javaw -cp "h2-1.4.200.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Server -web -ifNotExists -webAdminPassword webadminpass
@if errorlevel 1 pause
ifNotExists オプションを付けて起動する.
2021-11-08
H2データベースの接続URL
2019-09-26
Database URL Overview - Features にオプションの一覧がある.
H2データベースの起動オプション
2019-04-26
h2 1.4.199, linux
$ java -cp lib/h2-1.4.199.jar org.h2.tools.Server -web -ifNotExists -webAdminPassword xxxxx
h2-1.4.199で存在しないデータベースにアクセスしたときに新しいデータベースが作られないという問題が発生した.
ifNotExists があると,存在しないデータベースにアクセスしたときに自動でデータベースが作られる.
webAdminPassword がないと管理者ツールにアクセスできないようになった.起動オプションに渡すのはうまくいかなかった..h2.server.propertiesに webAdminPassword=9999 のように書けば良い.
2020-06-04 -webAdminPasswordオプションが動いたなぜだ?
起動オプションの一覧
code:txt
java -cp lib/h2-1.4.199.jar org.h2.tools.Server -?
Starts the H2 Console (web-) server, TCP, and PG server.
Usage: java org.h2.tools.Server <options>
When running without options, -tcp, -web, -browser and -pg are started.
Options are case sensitive. Supported options are:
-help or -? Print the list of options
-web Start the web server with the H2 Console
-webAllowOthers Allow other computers to connect - see below
-webDaemon Use a daemon thread
-webPort <port> The port (default: 8082)
-webSSL Use encrypted (HTTPS) connections
-webAdminPassword Password of DB Console administrator
-browser Start a browser connecting to the web server
-tcp Start the TCP server
-tcpAllowOthers Allow other computers to connect - see below
-tcpDaemon Use a daemon thread
-tcpPort <port> The port (default: 9092)
-tcpSSL Use encrypted (SSL) connections
-tcpPassword <pwd> The password for shutting down a TCP server
-tcpShutdown "<url>" Stop the TCP server; example: tcp://localhost
-tcpShutdownForce Do not wait until all connections are closed
-pg Start the PG server
-pgAllowOthers Allow other computers to connect - see below
-pgDaemon Use a daemon thread
-pgPort <port> The port (default: 5435)
-properties "<dir>" Server properties (default: ~, disable: null)
-baseDir <dir> The base directory for H2 databases (all servers)
-ifExists Only existing databases may be opened (all servers)
-ifNotExists Databases are created when accessed
-trace Print additional trace information (all servers)
-key <from> <to> Allows to map a database name to another (all servers)
The options -xAllowOthers are potentially risky.
For details, see Advanced Topics / Protection against Remote Access.
See also http://h2database.com/javadoc/org/h2/tools/Server.html