Search code examples
jdbcsqlitejrubysqlite3-ruby

JRuby and SQLite3


I'm trying to make work JRuby and SQLite3 with the following gems:

bouncy-castle-java (1.5.0146.1)

bundler (1.3.2)

dbd-jdbc (0.1.6 java)

dbi (0.4.5)

deprecated (2.0.1)

jdbc-sqlite3 (3.7.2.1)

jruby-launcher (1.0.15 java)

jruby-openssl (0.8.2)

json (1.7.7 java)

rack (1.5.2)

rack-protection (1.4.0)

rake (10.0.3)

rubygems-bundler (1.1.1)

rvm (1.11.3.6)

sinatra (1.3.5)

sqlite3 (1.3.7)

tilt (1.3.5)

and this code:

require 'java'
require 'dbi'
require 'dbd/Jdbc'
require 'jdbc/sqlite3'

dbh = DBI.connect(
  "DBI:jdbc:sqlite:db.sqlite",  # connection string
   '',                                 # no username for sqlite3
   '',                                 # no password for sqlite3
   'driver' => 'org.sqlite.JDBC')      # need to set the driver

But I have this error:

DBI::InterfaceError: Unable to load driver 'jdbc' (underlying error: wrong constant name jdbc) load_driver at /home/gl/.rvm/gems/jruby-1.7.3/gems/dbi-0.4.5/lib/dbi.rb:300 mon_synchronize at /home/gl/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/monitor.rb:211 load_driver at /home/gl/.rvm/gems/jruby-1.7.3/gems/dbi-0.4.5/lib/dbi.rb:242 _get_full_driver at /home/gl/.rvm/gems/jruby-1.7.3/gems/dbi-0.4.5/lib/dbi.rb:160 connect at /home/gl/.rvm/gems/jruby-1.7.3/gems/dbi-0.4.5/lib/dbi.rb:145 (root) at srv.rb:6

Have you got an idea?


Solution

  • I've just been trying to work this out myself, and eventually succeeded - the problem is that the driver name is now 'Jdbc', rather than 'jdbc' - capitalization is important, both in the connection string, and the require statement. If you change your connection string to "DBI:Jdbc:sqlite:db.sqlite" it should work fine.