H2
The h2 driver opens H2 databases through the JDBC driver. It supplies the Maven
dependency com.h2database:h2:2.5.252 and selects org.h2.Driver automatically.
URL format
h2:[<database>][;<h2-settings>][?<jdbc-options>]
h2: and h2:// open a private in-memory database. Other locations follow H2's JDBC syntax. An
optional // prefix is accepted for consistency with other rsql drivers.
| URL | Database |
|---|---|
h2:mem:example | Named in-memory database. |
h2:./example | Persistent database relative to the current directory. |
h2:///absolute/path/example | Persistent database at an absolute path. |
h2:tcp://localhost/~/example | Database on an H2 server. |
h2:mem:example;MODE=PostgreSQL | In-memory database with PostgreSQL compatibility settings. |
Options
H2 settings use semicolons; JDBC and Maven options use the query string.
| Option | Behavior / default |
|---|---|
;MODE=<mode> | H2 SQL compatibility mode, such as PostgreSQL. |
;USER=<user> / ;PASSWORD=<password> | H2 database credentials. |
Other H2 semicolon settings pass through unchanged. See JDBC options for coordinate formats, URL encoding, and classpath separators.
Examples
Start an in-memory session or query the H2 version:
rsql --url 'h2://'
rsql --url 'h2://' -- 'SELECT H2VERSION();'
Run SQL in the interactive session:
CREATE TABLE person (id INTEGER PRIMARY KEY, name VARCHAR(100));
INSERT INTO person VALUES (1, 'Ada');
SELECT * FROM person;
Use a persistent file, optionally with compatibility settings:
rsql --url 'h2:./example'
rsql --url 'h2:./example;MODE=PostgreSQL'
Downloads and offline use
H2 uses JDBC's shared Maven resolution and cache. POMs, checksums, and JARs are cached under the
user's OS cache directory in rsql/maven/repository; classpath artifacts are materialized in
rsql/maven/artifacts. Cached release dependencies are reused across sessions.
The first connection needs network access for uncached H2 dependencies and Ristretto's default Java runtime libraries. Offline use requires both the artifacts and runtime libraries to be cached locally. Ristretto executes H2 inside rsql without an external Java process.
Usage notes
Private in-memory databases disappear when their connection closes. Use a file URL to retain data between sessions. Each rsql JDBC connection owns a separate JVM, so named in-memory databases are not shared between connections.