Reputation:
EDIT: fixed wrong command. I have an h2 database on disk. How can I export it into in-memory? I have tried the following:-
java -cp h2/bin/h2*.jar org.h2.tools.Server -tcp
java -cp h2/bin/h2*.jar org.h2.tools.RunScript -url jdbc:h2:$(pwd)/restapi -user sa -script export.sql
java -cp h2/bin/h2*.jar org.h2.tools.RunScript -tcp -url jdbc:h2:mem:testdb -user sa -script db-dump.sql &
where export.sql contains:-
SCRIPT TO 'db-dump.sql
but When I try to connect to jdbc:h2:mem:testdb via the web console, I get following error:-
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)
Upvotes: 0
Views: 1202
Reputation: 8188
Server
tool doesn't have connection parameters and can't be used to create a new database; your first command is not valid. Did you check its output?
RunScript
tool can create a new database, but there is no reason to create an embedded in-memory database with it, such database will be available only to this tool and only while this process is running.
You need to take other steps instead.
SCRIPT TO 'db-dump.sql'
(if you have an open connection to it somewhere) or withjava -cp h2/bin/h2*.jar org.h2.tools.Script -url jdbc:h2:~/test -user sa -script db-dump.sql
if this persistent database is not opened anywhere.
java -jar h2/bin/h2*.jar
It should open a web browser window with H2 Console.
In this window specify jdbc:h2:mem:1;INIT=RUNSCRIPT FROM 'db-dump.sql'
as JDBC URL.
You can re-open such window by double-click on H2 Console icon in the system tray and you can use other commands from its context menu.
Note that if you type localhost:8082
in the browser directly, you will not be able to create a new database in it; you really need to open it from H2 (or you can copy URL with temporary security key from its status window available in context menu of tray icon).
Upvotes: 1