Over a million developers have joined DZone.

How to Remotely Connect to an In-Memory HSQLDB [Snippet]

DZone's Guide to

How to Remotely Connect to an In-Memory HSQLDB [Snippet]

In-memory databases are a common occurrence with unit tests, so let's take a look at how to remotely connect to an instance if you need to, say, debug some data or tests.

· Database Zone
Free Resource

Traditional relational databases weren’t designed for today’s customers. Learn about the world’s first NoSQL Engagement Database purpose-built for the new era of customer experience.

Very often, in-memory instances of HSQLDB are used in the context of unit tests; the unit test starts a database instance (eventually on a random port), provisions the database with some data, runs the test against the database end, then stops it.

Now, from time to time you need to debug unit tests, and sometimes you also need to manually run some queries on the in-memory database (using HSQLDB manager or any other software).

So here are the steps in order to be able to connect to an in-memory HSQLDB instance:

  • Start the DB in the “remote open db” mode. This is driven by the “server.remote_open” property that is false by default (you can look to the code of org.hsqldb.server.ServerProperties class to see other properties that might be interesting). The code that starts a database instance in remote open mode will look something like:
HsqlProperties props = new HsqlProperties();
props.setProperty("server.remote_open", true);
....add more properties here
Server server = new Server();
  • Connect to the data base instance. Now that the database has started, the next step is to connect to data base instance. Because we started an in-memory instance, the connection URL is a memory database URL that looks like jdbc:hsqldb:mem:instanceName. You will not be able to connect using this URL because neither the host and the port are available. Instead, you should use a server database URL that looks like: jdbc:hsqldb:hsql://host:port/instanceName

Learn how the world’s first NoSQL Engagement Database delivers unparalleled performance at any scale for customer experience innovation that never ends.

hsqldb ,database ,jdbc ,unit testing

Published at DZone with permission of Adrian CITU, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}