๐Ÿ’ง

H2 Database

H2 is a small, fast, embeddable SQL database written in Java, originally created by Thomas Mueller and now maintained by the open-source community. It ties for around #14 in real-world database usage (roughly 5% share) โ€” its huge footprint comes almost entirely from being swapped in as the test/dev database in Java and Spring Boot projects during automated testing.

๐Ÿ“Œ Quick facts
Type: Embedded relational database (SQL)
Made by: Thomas Mueller / open-source community
License: Free, open-source
Hosting: Embedded (in-process) or server mode
Primary use case: Automated testing and lightweight local development for Java/Spring apps
Jump to: Example queryGetting startedBest for

Example query

H2 speaks standard SQL and can run entirely in memory, which is exactly why test suites love it โ€” a fresh, disposable database on every run:

CREATE TABLE users (
   id INT PRIMARY KEY AUTO_INCREMENT,
   name VARCHAR(100) NOT NULL,
   email VARCHAR(150) UNIQUE
);

INSERT INTO users (name, email) VALUES ('Ada Lovelace', '[email protected]');

SELECT * FROM users WHERE name LIKE 'Ada%'; -- runs instantly, entirely in memory

Getting started

H2 is usually pulled in as a dependency rather than installed separately โ€” it just needs a JDBC connection string:

// add the H2 dependency, then connect in-memory (no server needed)
String url = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1";
Connection conn = DriverManager.getConnection(url, "sa", "");
๐ŸŽฏ Best for
Java and Spring Boot test suites, quick local prototyping, and small desktop tools that need a real SQL database without the overhead of installing and running Postgres or MySQL.