Grails: How-to access the default H2 in-memory database

When you use Grails for a new project, the default DBMS (DataBase Management System) is H2. A cool characteristic of this DBMS is its capability to handle in-memory tables: it is possible to create a database living in the RAM memory.

This is usually not the desired behavior, since Databases are by nature persistent entities. However, when developing a new application, having the possibility to use an in-memory database may speed up the development process, given that the table structure may vary quite frequently.

Grails makes use of H2 in-memory tables by default. If you create a new application and define a new domain class, Grails will take care of creating a suitable table for your class.
Sometimes it is useful to actually see the tables that Grails generated for us. Assuming you are running your web server (e.g.: Apache) on localhost port 80 and that your app name is myApp, while running the application you can access the in-memory database browsing to: http://localhost/myApp/dbconsole/. It should be possible to login immediately by clicking on “Connect”. From there you will be able to see and manipulate your in-memory database.

If you wish your Grails application to use a different database, you can start here.

Grails: How-to access the default H2 in-memory database

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s