Вот пример, который работает с JRuby 1.6.6 (в режиме сжатия Ruby 1.8) с jdbc-sqlite3 3.7.2.
require 'rubygems'
require 'jdbc/sqlite3'
require 'java'
org.sqlite.JDBC # load the driver so DriverManager detects it
#Java::OrgSqlite::JDBC # alternate means of same
connection = java.sql.DriverManager.getConnection 'jdbc:sqlite:test.sqlite3'
begin
statement = connection.createStatement
begin
statement.executeUpdate("create table user (name varchar, pass varchar)")
statement.executeUpdate("insert into user values ('alice', 1234)")
statement.executeUpdate("insert into user values ('bob', 5678)")
statement.executeUpdate("insert into user values ('charlie', 'asdf')")
rs = statement.executeQuery("select * from user")
begin
puts "user\tpass"
while rs.next
puts ["#{rs.getString(1)}",
"#{rs.getString(2)}"].join("\t")
end
ensure
rs.close
end
ensure
statement.close
end
ensure
connection.close
end
Выход:
$ rm -f test.sqlite3; ruby sql.rb
user pass
------------
alice 1234
bob 5678
charlie asdf