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.
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
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", "");