Ruby Driver for HSQLDB Released

| by Obie Fernandez on Oct 11, 2006. Estimated reading time: 2 minutes |

A Ruby driver for HSQLDB has been released on RubyForge by Jared Richardson, one of the authors of the Pragmatic Programmer book Ship it! A Practical Guide to Successful Software Projects. Jared is also an article contributor to, most recently writing about dealing with legacy code. This is Jared's second Ruby database driver. The first was for Ingres, but hasn't been released by CA yet.

The driver uses the Yet Another Java Bridge project to access Java objects from within Ruby, which is a very different approach to Java-Ruby interaction as that of JRuby, which gives you Ruby objects inside of Java. I asked Jared to comment on the YAJB project:

I'm not sure about the performance. I've only used in a testing situation, but I've not noticed any performance impact. But again, I haven't attempted to put it under any type of load. The YAJB project serializes the information over a socket, so it's going to be the slowest available option. But given the small amount of data that a Rails app is usually moving, I thought it was a safe bet. It was also extremely easy to get up and running.

HSQLDB, which used to be known as HypersonicSQL, is described as the leading SQL relational database engine written in Java. It has a JDBC driver and supports a rich subset of ANSI-92 SQL. Quite similar to SQLite, it has a fast database engine which offers both in-memory and disk-based tables and supports embedded and server modes.

You can install the driver easily as a RubyGem by typing gem install hypersonic, which will pull the project files off of RubyForge and install them locally. The binary distribution consists of the hsqldb.jar and a 225-line Ruby file named Hypersonic.rb. Grab the source distribution zip from the project site to get a rakefile and functional test that allows easy testing of your setup.

The following code sample illustrates use of the driver:

@h =
@h.connect("jdbc:hsqldb:file:testdb2", "sa", "")
@h.execute_update("DROP TABLE #{@temp_table_name} IF EXISTS")
@h.execute_update("CREATE TABLE #{@temp_table_name} (c1 INTEGER, c2 VARCHAR)")
@h.execute_update("INSERT INTO #{@temp_table_name}(c1, c2) VALUES (32, 'howdy')")
rs = @h.execute_query("SELECT * FROM #{@temp_table_name}")
rs = @h.execute_query("SELECT COUNT(*) FROM #{@temp_table_name}")

I also asked Jared to comment on plans to integrate his driver with ActiveRecord, and he said:

ActiveRecord integration is about a quarter of the way done and the client has shifted priorities... that is to say, they're not paying me to finish the AR portion at this time. :) So the AR integration is on hold at the moment. If anyone else wanted to pick it, I'd be glad to share the work I've done though. Of if someone wanted to contract with me to complete the work, I'd be willing to work on it. Right now I just don't have the time to complete it in my evenings and weekends.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

HSQLDB using ActiveRecord-JDBC for JRuby by Nick Sieger

Note that ActiveRecord-JDBC (which is an JRuby/ActiveRecord driver for multiple JDBC databases) supports HSQLDB also. If you're willing to go the JRuby route, we'd be interested to hear your experiences with it on the jruby-extras mailing list.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss