DEV Community

Horia Constantin
Horia Constantin

Posted on

Inspecting in-memory HSQLDB

Sometimes, for automatic testing of your Java application, you need to configure a DB connection. Most of the time the decision is to go for an in-memory database and HSQLDB is a prime candidate.

Some other times, your tests will be failing and it would be great to see the DB status before the failure. I already knew of the option of running HSQLDB as a server, but a colleague showed me a simpler way, with less configuration.

Simply add the following lines to the beginning or the test:

System.setProperty(“java.awt.headless”, “false”); // to prevent an exception related to awt running headless
DatabaseManagerSwing.main(new String[]{“--url”, “jdbc:hsqldb:mem:testdb”, “--user”, “sa”, “--password”, “”}); //to launch a separate a simple DB-inspector window
Enter fullscreen mode Exit fullscreen mode

Normally, you’re going to put a breakpoint in your test right before the failing assertions. If the DB-inspector window freezes it’s because the breakpoint is configured to stop all threads. You will need to configure your IDE to not stop the DB-inspector thread (on IntelliJ IDEA, right-click on the breakpoint and you’ll get the menu that allows you to change this).

References:

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay