act:ualise | technology

03 Jul, 2009

Viewing Grails’ in memory HSQLDB

Posted by: j pimmel In: database|development

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!

Tags: ,

6 Responses to "Viewing Grails’ in memory HSQLDB"

1 | deebeeNo Gravatar

August 4th, 2009 at 11:11 am

Avatar

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 | FlorentNo Gravatar

August 12th, 2009 at 12:38 am

Avatar

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 | Adam EvansNo Gravatar

October 1st, 2009 at 4:52 am

Avatar

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 | Hitesh BagchiNo Gravatar

November 7th, 2009 at 10:27 pm

Avatar

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

5 | Javid JamaeNo Gravatar

January 25th, 2010 at 10:17 pm

Avatar

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 | Dalton jorgeNo Gravatar

March 15th, 2010 at 7:27 pm

Avatar

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”

Comment Form

About

act:ualise | technical blog

notes, observations and obssessions on software quality, agile software development, testing and grails


part of the EnergizedWork experiment