I'm now coding a prototype of my product (more on that in the near future) and one of the first things I was looking for was a repository to keep data. The repository needs to be embedded in my software with no external server running. After considering several alternatives, including exotic ones like RDF repositories, I decided to go for a relational database. Naturally, I was thinking of Oracle's Berkeley DB. It is a highly regarded embedded database, probably the best on the market.The main obstacle was the license: it is free if your software is free. So, I started looking for alternatives.
I had two main alternatives now. First one, Java DB. This is a new feature in JDK 6, which is actually a re-branding of Apache Derby, another popular embedded database. The next option was HSQLDB, the database engine used in Open Office. For those not familiar with Open Office, let's just say that if Open Office is the alternative to Microsoft Office then HSQLDB is the alternative to the Jet database engine (or the later "desktop" versions of SQL Server) used by Microsoft Access. Open Office has an Access like application called Base, which uses it. Needless to say, the Microsoft alternatives were out of the question since I'm working on a Mac.
Then I came across an interesting product: H2. The H2 database engine is a free, open source, fully functional relational database management system written in Java. It can run in embedded mode or as a server. What caught my eye was a claim by the developers that H2 is faster than both HSQLDB and Apache Derby. Being an innovator myself, I like disruptive new products, hence, I decided to give it a shot.
Installation was a breeze. I was up and running in literally minutes. What you get from their site is a zip file (installer if you're on Windows) and a PDF manual. That's it. You unzip the file and you're good to go. The manual is very useful, and got me started in no time. Once you start the server, by using a Java archive, it starts a web server which provides a web client for working with your database. So, again, unzip, run a Java command and that's it. You got a fully featured database server AND a database management application working. BTW, starting the server takes about a second on my MacBook Pro, even when I've got over 10 other applications running in the background.
Working with H2
H2 supports SQL and JDBC, so it's much like any other database. The data is kept in a few compact files which you specify in your connection URL. If the files does not exist, they are created on the fly and you can start using them immediately. Backing up just means backing up your files. For those familiar with Jet, it is pretty much the same only much smaller and faster. The web client is great for viewing your database structure, viewing/editing table data and executing SQL commands. If you're looking for a tool that will help you design your database (i.e. you're too lazy to write the SQLs for creating the tables by hand), you can also use the Open Office Base wizards and table views or use other tools which support JDBC, like SQuirreL SQL (free, open source and cross platform).
The Developer Perspective
Since I'm working on a prototype, agility is my main concern. I'm using the Spring Framework JDBC Templates and it is working perfectly together. H2 also supports Hibernate, but I don't really need it at the moment. I can create new queries in minutes. I'm working in embedded mode and starting the server is very fast, usually less than a second, and it has a minimal memory footprint. This is important since I often want to execute simple tests and get instant results. I didn't get a chance to measure its' SQL execution performance, but that will happen in the near future.
I had one issue: once my process starts it locks the file, so I cannot see what's going on in the database using another client. I posted a question in the H2 Google group and quickly got a response, by the lead developer, that I can continue to work in embedded mode and still open up a port for remote connections. It took me about a minute to set this up and it just works. This is what I like about H2, it is very simple and easy to use.
I'm happy with H2. It is just what I needed. It is a breeze to install, it is compatible with my ecosystem and it is quietly delivering results without disturbing my work and becoming a burden. I haven't used it for production systems or for heavy data crunching, but for my needs it works great. If you're writing a Java software and you need a simple, instant, persistent storage, this is a viable alternative to consider. H2 is currently in beta and it is still under development. This is something to keep an eye on.