views:

604

answers:

4

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'.

+1  A: 

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.

Don Werve
A: 

Strange it worked fine for me , on my ubuntu 9.04 box : i m using only the standard ubuntu packages and my DB configuration is :

development:
 adapter: jdbc
 driver: org.apache.derby.jdbc.EmbeddedDriver
 url: jdbc:derby:[myapp];create=true
lapinferoce
A: 

The ClientDriver is in derbyclient.jar

Bryan Pendleton
A: 

Further to Don's answer, I was getting this error when using the ClientDriver without a username/password: The driver encountered an error: java.sql.SQLNonTransientConnectionException: Password length (0) is outside the range of 1 to 255.

Setting username/password in database.yml fixed the problem!

Chris Paton