act:ualise | technology

agile software development, software quality, scaling, testing and other tech

Viewing Grails’ in memory HSQLDB

| 7 Comments

DatabaseManagerGrails comes with HSQLDB as it’s in-memory db and it’s not difficult to inspect it, but there’s a simpler way than many realise and it’s built into every Grails installation, bundled in the HSQLDB jar lib.

I have found this trick is useful when inspecting DB state during integration test execution.

Just add the following line of code to somewhere in your application.

org.hsqldb.util.DatabaseManager.main()

When that line gets triggered from a running grails app you will see the prompt window above appear on your desktop.

All you need to then do is tweak the DB url (remove the . and replace with DB name) to reflect your datasource properties for the in-memory DB, in my case

jdbc:hsqldb:mem:devDB

That’s it! You should then see the Database schema browser below.

DatabaseManager_session

One important caveat – this DB tool issues a System.exit() which terminates your Grails app when you close so be sure to remove that line when you have done inspecting!

7 Comments

  1. Excellent tip, that saved a lot of trouble in setting up a “real” DB to be able to view inspect the generated DB.

    Thanks a lot!!!

  2. Hi,

    Great tip, I was wondering yesterday how to connect to the in-memory hsqldb.

    I found that you could use org.hsqldb.util.DatabaseManagerSwing.main() for a better-looking manager

    Thanks for the article

  3. I stick the below code in the bootstrap init function. You will need to add ‘import grails.util.Environment’ also . Means no config to complete and the dbmanager popsup on deploy in dev mode.

    if(Environment.current == Environment.DEVELOPMENT){
    String[] databaseManagerOptions = ['--url', 'jdbc:hsqldb:mem:devDB'];
    org.hsqldb.util.DatabaseManagerSwing.main(databaseManagerOptions)
    }

  4. Great tip! Simple and and yet enormously helpful! Thanks!

  5. You can use the “–noexit” flag to avoid the System.exit() call when you close the window.

    Like this:

    String[] databaseManagerOptions = ['--url', 'jdbc:hsqldb:mem:devDB', '--noexit'];

  6. Hi,

    Nice tip!
    I prefer use the DatabaseManager separated from the app, so I do this:

    1) in a new terminal, I change dir to the app’s path;
    2) at prompt: “java -cp /lib/hsqldb-1.8.0.10.jar org.hsqldb.util.DatabaseManager”

  7. Pingback: Grails Interview Questions ( now with some Answers! ) | Tomás Lin’s Programming Brain Dump

Leave a Reply

Required fields are marked *.

*