Cogs and Levers A blog full of technical stuff

H2

H2 is a relational database written entirely in Java. It has an extremely small footprint and has an in-memory mode making it an excellent choice for embedded applications.

In today’s post, I’ll take you through using the H2 shell.

Shell

Once you’ve downloaded H2 from their site, you can get a database created and running using the shell. You can invoke the shell with the following command:

java -cp h2-1.4.190.jar org.h2.tools.Shell -url jdbc:h2:~/testdb

I’m using version 1.4.190 here. The -url command line directs us to the file of the database that we’ll create/open.

Once the shell is running, you’re presented with a sql> prompt. You can start creating your table definitions. The documentation on the website is quite extensive with the supported sql grammar, functions and data types.

Further development

Now that you’ve created a database, you can write java applications using JDBC to run queries against your H2 database.