Skip to content

Instantly share code, notes, and snippets.

@virtualadrian
Forked from tachesimazzoca/README.md
Created November 18, 2017 01:49
Show Gist options
  • Select an option

  • Save virtualadrian/8e6a9227c5ffcfc6e9a8f2ce17675bc0 to your computer and use it in GitHub Desktop.

Select an option

Save virtualadrian/8e6a9227c5ffcfc6e9a8f2ce17675bc0 to your computer and use it in GitHub Desktop.
H2 Database Scripts

H2 Database Scripts

Make a directory, like ~/.h2, and put the following files in it.

  • ~/.h2/lib/h2-*.jar: Get the latest h2-*.jar file from http://www.h2database.com/.
  • ~/.h2/bin/h2-server: org.h2.tools.Server
  • ~/.h2/bin/h2-shell: org.h2.tools.Shell
  • ~/.h2/db/ : H2 data files *.mv.db

You may add the path ~/.h2/bin to your env $PATH.

$ vi ~/.bash_profile
...
PATH=$HOME/.h2/bin:$PATH
export PATH
...

To start or stop H2 Database server, run h2-server (start|stop).

# Start TCP server in background
$ h2-server start
TCP server running at tcp://x.x.x.x:9092 (only local connections)
...
# Stop TCP server "tcp://localhost"
$ h2-server stop

h2-shell is just a wrapper script for org.h2.tools.Shell. You can use the same command-line options.

$ h2-shell -help
...
$ h2-shell -url "jdbc:h2:tcp://localhost/~/.h2/db/test" -user "sa"
...
#!/bin/sh
cd `dirname ${0}`/..
case $1 in
help)
java -cp lib/h2-*.jar org.h2.tools.Server -?
;;
start)
java -cp lib/h2-*.jar org.h2.tools.Server -tcp -baseDir db &
;;
stop)
java -cp lib/h2-*.jar org.h2.tools.Server -tcpShutdown "tcp://localhost"
;;
*)
echo "Usage ${0} (help|start|stop)"
;;
esac
#!/bin/sh
cd `dirname ${0}`/..
java -cp lib/h2-*.jar org.h2.tools.Shell "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment