Start and setup in-memory DB using Spring

martin picture martin · Jan 12, 2011 · Viewed 38.7k times · Source

I'm writing a small demo application in Java using Spring, that needs to have access to a database. It should run on different machines and it would be far too much effort to setup a real database. Therefore I want to use an embedded one.

The DB has a given schema (two tables) and some (very few) pre-defined entries. I'm looking for a simple way to start an in-memory database, create the tables and fill in the data. All of this should happen while initializing the Spring context.

My approach would be to use H2 as my database and then maybe Spring Batch to load the data from csv- or xml-files. However I was hoping there might be an easier way to achieve this. Are there any databases/frameworks/tools that can do this out-of-the-box?

It would only take a few SQL-commands to set-up everything I need. I'm looking for a way to do this in a Spring-environment as simple as possible.

Answer

axtavt picture axtavt · Jan 12, 2011

Spring has some built-in embedded database support, see embedded database support in the documentation.