Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using embedded Derby with JRuby on Rails

Attempting to use JRuby 1.2.0 and Rails 2.3.2 with an embedded Derby database. I've copied derbytools.jar and derby.jar to $RUBY_HOME/lib, yet rake db:migrate still gives:

The driver encountered an error: 
    cannot load Java class org.apache.derby.jdbc.ClientDriver

Aaaand... I played a hunch and figured it out. So, I'll post this here in case somebody else runs into the same problem I did.

Almost all the documentation I found online has the following database.yml configuration for Derby:

development:
    adapter: jdbc
    driver: org.apache.derby.jdbc.ClientDriver
    url: jdbc:derby:[db];create=true
    username: xxx
    password: xxx

This probably works fine for a client/server setup, but for an embedded Derby setup, you need this:

development:
    adapter: jdbc
    driver: org.apache.derby.jdbc.EmbeddedDriver
    url: jdbc:derby:[db];create=true
    username: xxx
    password: xxx

Note the 'EmbeddedDriver', and not 'ClientDriver'.

like image 684
Don Werve Avatar asked Nov 06 '22 21:11

Don Werve


1 Answers

Going to answer, because I hate seeing that red block in my profile.

There's also a subtle bug in ActiveRecord-JDBC when you use embedded derby -- if you don't give it a username and a password, nothing works. I've tracked down the cause of this bug, and am working on submitting a patch, but if you run into the same problem I did, let me know, and I'll post the code here.

like image 139
Don Werve Avatar answered Nov 12 '22 18:11

Don Werve