Archive for December, 2013

Inspect in-memory Hsqldb database

In Java, it is common to use in-memory databases for testing proposes. Hsqldb (http://hsqldb.org/) is a great alternative to this. But, what’s happen if your test fail? In some cases, is necessary to inspect the database contents to ensure everything goes right. So, how can we do that?

Suppose that your database configuration is like:

Connection c =
DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", "");

First, make sure to set a breakpoint at the specific line of your code that you want to inspect. Then, you have to run the “database inspector”:

org.hsqldb.util.DatabaseManagerSwing.main(
  new String[] { "--url", "jdbc:hsqldb:mem:testdb",
    "--user", "sa", "--password", ""});

There are two ways to run that (line of) code:

  1. Add that code to the setUp()/@Before method of your testcase
  2. In Eclipse, open the Display view, paste the code, select it, right-click and “Inspect” (or CTRL+SHIFT+I)

Once runned, a window will be shown, with a classic db-manager:

hsqldb-manager

Then, do the SQL queries as you need.


Enhanced Links