H2 Database Installation Guide

Requirements

  • Java 11 or higher
  • Any operating system that supports Java (Windows, Linux, macOS, etc.)

Installation Methods

Method 1: Download ZIP Package

  1. Visit the official website download page: https://www.h2database.com/html/download.html
  2. Download the "Platform-Independent Zip" version
  3. Extract the downloaded ZIP file to any directory, such as: C:\h2 or /opt/h2

Method 2: Maven Dependency

If you are using a Maven or Gradle Java project, you can add the dependency directly:

Maven:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>2.2.224</version>
</dependency>

Gradle:

implementation 'com.h2database:h2:2.2.224'

Method 3: Windows Installer

  1. Download the "Windows Installer" version
  2. Run the installer and follow the wizard to complete installation

Configure Environment Variables (Optional)

If you downloaded the ZIP package and want to use H2 directly from command line:

Windows:

  1. Right-click "This PC" → "Properties"
  2. Click "Advanced System Settings"
  3. Click "Environment Variables"
  4. Find "Path" in System Variables and click "Edit"
  5. Add the H2 bin directory path

Linux/macOS:

export PATH=$PATH:/opt/h2/bin

Verify Installation

Using Command Line

After extracting, run in command line:

java -jar h2.jar

This will start the H2 Console web interface.

Using JDBC Connection

Connect to H2 database in Java code:

// Embedded mode
String url = "jdbc:h2:mem:testdb";
Connection conn = DriverManager.getConnection(url, "sa", "");

// File database
String url = "jdbc:h2:file:./data/testdb";
Connection conn = DriverManager.getConnection(url, "sa", "password");

Using H2 Console

  1. Run command: java -jar h2.jar
  2. Open browser: http://localhost:8082
  3. Default username: sa, password is empty

Connection URL Formats

H2 supports various connection URL formats:

ModeURL ExampleDescription
In-memoryjdbc:h2:mem:testdbData stored in memory
Embedded filejdbc:h2:file:./data/testdbData stored in file
TCP serverjdbc:h2:tcp://localhost:9092/testdbClient-server mode
TCP encryptedjdbc:h2:ssl://localhost:9092/testdbSSL encrypted connection
PostgreSQL compatiblejdbc:h2:postgres://localhost:5432/testdbPostgreSQL protocol compatible

Common Issues

Port Already in Use

H2 uses port 9092 (TCP mode) and 8082 (Web Console) by default. If ports are occupied, you can specify other ports in the connection URL.

Java Version Issues

Make sure Java 11 or higher is installed. Check with:

java -version

Driver Not Found

Make sure the H2 JAR file is in the classpath. If using Maven project, ensure the dependency is correctly added.