0

I try to put this simple MRI script to work in jRuby but i get the error below. I installed the same gem as in my MRI I don't wanna use JDBC of Active Record, just make a simple connection and query, what should i do ?

C:\jruby-1.7.4\bin>jruby -S gem list --local 

gives

..
ruby-oci8 (2.1.0 x86-mingw32)
..

the script

require 'oci8'

$conn = OCI8.new('test','test','dbcm.cm_121')

sql = %q{
  select * from table
 }

$conn.exec(sql).fetch_hash do |r|
  r.each {|key, value| puts "#{key} is #{value}"}
  puts ""
end

$conn.logoff

the error

C:\jruby-1.7.4\test>jruby fetch_sql.rb
LoadError: no such file to load -- oci8lib_jruby191
  require at org/jruby/RubyKernel.java:1054
  require at C:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:36
   (root) at C:/jruby-1.7.4/lib/ruby/gems/shared/gems/ruby-oci8-2.1.0-x86-mingw32/lib/oci8.rb:43
  require at org/jruby/RubyKernel.java:1054
   (root) at C:/jruby-1.7.4/lib/ruby/shared/rubygems/custom_require.rb:1
   (root) at fetch_sql.rb:1
4

1 回答 1

0

Seems it it is not possible, otherwise please let us know. Here the shortest/simplest example i could produce using jdbc

require 'java'

#source: http://www.oracle.com/technetwork/articles/dsl/jruby-oracle11g-330825.html

java_import 'oracle.jdbc.OracleDriver'
java_import 'java.sql.DriverManager'

begin
  oradriver = OracleDriver.new
  DriverManager.registerDriver oradriver
  user = 'xxx'
  passwd = 'xxx'
  url = 'jdbc:oracle:thin:@xxxxxx:9999:xxxx'
  conn = DriverManager.get_connection url, user, passwd
  select_sql = "select * from resources"
  select_stmt = conn.create_statement
  rset = select_stmt.execute_query select_sql
  while (rset.next)
    puts "    resource [#{rset.getInt(1)}, #{rset.getString(2)}]"
  end
rescue
  puts "Failed executing Oracle demo from JRuby ", $!, "\n"
ensure
  select_stmt.close
  conn.close_connection
end
于 2013-06-24T15:13:46.390 回答