DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Valkey: Bringing Key-Value Databases to Enterprise Java
  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Trending

  • DZone's Article Submission Guidelines
  • How to Submit a Post to DZone
  • You Do Not Need a PhD to Become an AI Engineer: The Essential Skill Stack
  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. An Overview of 3 Java Embedded Databases

An Overview of 3 Java Embedded Databases

Embedded databases move management from standalone systems to your app. Let's take a look at HSQLDB, H2, and Apache Derby to see how they can work with Java apps.

By 
Swathi Prasad
·
Updated May. 05, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
89.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

An embedded database is a database that is incorporated as a connected part of an application.

Embedded databases can be very helpful during the development or testing phases because they are lightweight, fast, improve testability, and ease of configuration. We have plenty of choices for incorporating embedded databases. Be sure to apply pragmatism while picking one because each has their own pros and cons.

Image title

In this article, I will go over some of the embedded databases for working with Java.

HSQLDB (HyperSQL Database)

HyperSQL Database conforms to the SQL standard and JDBC specifications.

It supports all the core features that are expected from a modern relational database. It can be run either in embedded or server mode. HyperSQL database is built in pure Java and supports JDK 5, 6, 7 and 8 in HyperSQL 2.x.

It provides support for CallableStatement and PreparedStatement, including batch executions to speed up data processing. With version 2.3.x onwards, it supports two-phased locking and multiversion concurrency control.

The package contains a JAR file which contains the required components such as HyperSQL RDBMS Engine and the JDBC driver for embedding HyperSQL in a Java application.

Connection

A connection can be established as follows:

//load the JDBC driver
Class.forName("org.hsqldb.jdbcDriver" );
Connection connection = DriverManager.getConnection("jdbc:hsqldb:testdb", "sa", "");


Check the official documentation for more details.

H2 

H2 is the Java SQL database. It's open source and supports the JDBC API. It supports both embedded and server modes and provides support for row-level locking and multiversion concurrency.

Connection

A connection can be established as follows:

//load the driver
Class.forName("org.h2.Driver" );
Connection connection = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");


Here,  ~/  indicates user home directory.

In their official documentation, the comparison of H2 with other database engines is quite comprehensive, which makes it easier to pick the one of your choice.

Apache Derby

Apache Derby is an open source relational database implemented entirely in Java and available under the Apache License, Version 2.0. It is based on Java, JDBC, and SQL standards.

It supports client/server and embedded modes. All the standard features of a relational database are supported by Derby.

Connection

Use derby.jar in your application. A connection can be established as follows:

//load the driver
Class.forName(“org.apache.derby.jdbc.EmbeddedDriver”);
Connection c = DriverManager.getConnection("jdbc:derby:testdb1;create=true”);

Summary

The JAR files provided by these database providers contain all the necessary components for CRUD operations. Working with embedded databases is easy and fun. You just need to remember a few tips to make your application work with embedded databases successful!

Relational database Java (programming language)

Published at DZone with permission of Swathi Prasad. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Valkey: Bringing Key-Value Databases to Enterprise Java
  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook