I am writing a little demo application in Java using Spring, that must get access to a database. It will operate on different machines and it might be way too much effort to create a genuine database. Therefore I wish to make use of an embedded one.

The DB includes a given schema (two tables) plus some (very couple of) pre-defined records. I am searching for an easy method to start an in-memory database, produce the tables and complete the information. All this should happen while initializing the Spring context.

My approach is always to use H2 as my database after which maybe Spring Batch to load the information from csv- or xml-files. However was wishing there can be an simpler way to do this. What are the databases/frameworks/tools that may do that out-of-the-box?

It might just take a couple of SQL-instructions to create-up everything I want. I am searching for a method to do that inside a Spring-atmosphere as easy as possible.

Spring has some built-in embedded database support, see 12.8 Embedded database support .

Spring 3 added more support for embedded databases beginning from three with the aid of jdbc:embedded-database element. Read this tutorial to learn more.

I'd also recommend using Derby because it comes bundled up with JDK 6.

With H2, you can initialize the database within the database URL itself. Example: you've got a SQL script 'start.sql' that consists of all of the scripts to initialize. This could likewise incorporate creating the tables from CSV file. Then make use of a database Link to the shape jdbc:h2:~/temp/test;init=runscript from '~/temp/start.sql'. The beginning.sql could seem like this (it is really an example I am focusing on anyway - it shows how you can create tables from the CSV file):

create table if not exists location(id int primary key, country varchar, 
region varchar, city varchar, postalCode varchar, latitude float, longitude float, 
metroCode varchar, areaCode varchar) 
as select * from csvread('~/Downloads/GeoLiteCity/GeoLiteCity-Location.csv');

create table if not exists blocks(start long, end long primary key, location int) 
as select * from csvread('~/Downloads/GeoLiteCity/GeoLiteCity-Blocks.csv');

create alias if not exists ip2id deterministic as $$
long ip2id(String s) {
  String[] x = s.split("\\.");
  return (Long.parseLong(x[0]) << 24) + (Long.parseLong(x[1]) << 16) +
    (Long.parseLong(x[2]) << 8) + Long.parseLong(x[3]);
} $$;

create alias if not exists id2ip deterministic as $$
String id2ip(long x) {
  return (x >> 24) + "." + ((x >> 16) & 255) + "." + 
      ((x >> 8) & 255) + "." + (x & 255);
} $$;

HSQLDB is a great choice.

If you are using Grails it arrives with HSQLDB already setup for you personally. You can include sample data towards the conf/grails-application/BootStrap class's init method. It does not have any simpler than that.