Sqlite Connect with ruby java bridge

252 Views Asked by At

I am trying to connect to an sqlite database using Rjb and the JDBC driver from https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage

I cannot work out how to call the following Java using Rjb:

Class.forName("org.sqlite.JDBC")

Has anyone connected to sqlite using Rjb with success?

The RJB code I have so far is as follows and is throwing the exception 'java.sql.SQLException: No suitable driver found for jdbc:sqlite:/Users/obrientimothya/Dropbox/development/vle/db/development.sqlite3'

Connection                  = Rjb::import 'java.sql.Connection'
DriverManager               = Rjb::import 'java.sql.DriverManager'
SQLException                = Rjb::import 'java.sql.SQLException'
DriverManager.registerDriver(Rjb::import('org.sqlite.JDBC'))
connection = DriverManager.getConnection("jdbc:sqlite:/Users/obrientimothya/development.sqlite3")
1

There are 1 best solutions below

0
On

I ended up solving this by adding the system property jdbc.drivers when loading the JVM...

Rjb::load( classpath, ['-Djdbc.drivers=org.sqlite.JDBC','-Xms128M', '-Xmx256M'] )

This tells java.sql.DriverManager to load the sqlite jdbc driver class itself, eliminating the need for a Class.forName() call.