简体   繁体   English

SQLite与Ruby Java桥连接

[英]Sqlite Connect with ruby java bridge

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 我正在尝试使用Rjb和JDBC驱动程序从https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage连接到sqlite数据库

I cannot work out how to call the following Java using Rjb: 我不知道如何使用Rjb调用以下Java:

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

Has anyone connected to sqlite using Rjb with success? 有没有人成功使用Rjb连接到sqlite?

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' 到目前为止,我拥有的RJB代码如下,并引发异常“ java.sql.SQLException:找不到适用于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")

I ended up solving this by adding the system property jdbc.drivers when loading the JVM... 我最终通过在加载JVM时添加系统属性jdbc.drivers解决了这一问题。

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. 这告诉java.sql.DriverManager加载sqlite jdbc驱动程序类本身,从而无需Class.forName()调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM