102

How to use H2 database's integrated managment frontend?

For operations such as create table, alter table, add column, and so on.

3

10 Answers 10

91

I like SQuirreL SQL Client, and NetBeans is very useful; but more often, I just fire up the built-in org.h2.tools.Server and browse port 8082:

$ java -cp /opt/h2/bin/h2.jar org.h2.tools.Server -help
Starts the H2 Console (web-) server, TCP, and PG server.
Usage: java org.h2.tools.Server 
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
[-webPort ]       The port (default: 8082)
[-webSSL]               Use encrypted (HTTPS) connections
[-browser]              Start a browser and open a page to connect to the web server
[-tcp]                  Start the TCP server
[-tcpAllowOthers]       Allow other computers to connect - see below
[-tcpPort ]       The port (default: 9092)
[-tcpSSL]               Use encrypted (SSL) connections
[-tcpPassword ]    The password for shutting down a TCP server
[-tcpShutdown ""]  Stop the TCP server; example: tcp://localhost:9094
[-tcpShutdownForce]     Do not wait until all connections are closed
[-pg]                   Start the PG server
[-pgAllowOthers]        Allow other computers to connect - see below
[-pgPort ]        The port (default: 5435)
[-baseDir ]        The base directory for H2 databases; for all servers
[-ifExists]             Only existing databases may be opened; for all servers
[-trace]                Print additional trace information; for all servers
2
  • 2
    In 1.4, you run the console with java -jar /opt/h2/bin/h2.jar. Feb 16, 2016 at 19:22
  • 3
    Also consider java -cp /opt/h2/bin/h2.jar org.h2.tools.Shell.
    – trashgod
    Feb 16, 2016 at 23:12
33

How about the H2 console application?

3
  • 15
    +0 e.g. java -cp h2*.jar org.h2.tools.Console Sep 12, 2011 at 11:07
  • 3
    Console application is great and can be accessed over http: localhost:8082 Apr 3, 2014 at 22:00
  • 2
    Under eclipse (if you have the H2 dependency, via maven for example) open the class org.h2.tools.Console then right click and "run as Java Application"
    – pdem
    Jan 26, 2018 at 9:25
20

I use sql-workbench for working with H2 and any other DBMS I have to deal with and it makes me smile :-)

2
  • I am using it with derby Jun 10, 2017 at 6:35
  • It needs 32-bit Java installed in your system Sep 27, 2018 at 8:27
13

I would like to suggest DBEAVER .it is based on eclipse and supports better data handling

0
7

There's a shell client built in too which is handy.

java -cp h2*.jar org.h2.tools.Shell

http://opensource-soa.blogspot.com.au/2009/03/how-to-use-h2-shell.html

$ java -cp h2.jar org.h2.tools.Shell -help
Interactive command line tool to access a database using JDBC.
Usage: java org.h2.tools.Shell <options>
Options are case sensitive. Supported options are:
[-help] or [-?]        Print the list of options
[-url "<url>"]         The database URL (jdbc:h2:...)
[-user <user>]         The user name
[-password <pwd>]      The password
[-driver <class>]      The JDBC driver class to use (not required in most cases)
[-sql "<statements>"]  Execute the SQL statements and exit
[-properties "<dir>"]  Load the server properties from this directory
If special characters don't work as expected, you may need to use
 -Dfile.encoding=UTF-8 (Mac OS X) or CP850 (Windows).
See also http://h2database.com/javadoc/org/h2/tools/Shell.html
3

I haven't used it, but RazorSQL looks pretty good.

1
  • 5
    And it is not free. "The download expires 30 days after the first use. After the expiration, a registration code / serial number must be purchased to continue using RazorSQL. "
    – btpka3
    Aug 17, 2011 at 5:50
1

If you are running it as an embedded database in spring I use the following configuration to enable the built in web client when the main app is running:

<!-- Run H2 web server within application that will access the same in-memory database -->
<bean id="h2Server" class="org.h2.tools.Server" factory-method="createTcpServer" init-method="start" destroy-method="stop" depends-on="h2WebServer">
    <constructor-arg value="-tcp,-tcpAllowOthers,-tcpPort,9092"/>
</bean>
<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
    <constructor-arg value="-web,-webAllowOthers,-webPort,8082"/>
</bean>
1

I use DbVisualizer a lot for H2-db administration.

There exists a free version:

https://www.dbvis.com/download/

1

I would suggest Jetbrain's IDE: DataGrip https://www.jetbrains.com/datagrip/

1
  • Its not free, it comes with 30 days trial Sep 27, 2018 at 8:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.