views:

46

answers:

2

I'm trying to write a jruby script that connects to an oracle database using jdbc.

Thusfar I've got:

require 'rubygems'
require 'jdbc_adapter'
require 'active_record'
require 'active_record/version'

ActiveRecord::Base.establish_connection(  
 :adapter => 'jdbc',  
 :driver => 'oracle.jdbc.driver.OracleDriver',
 :url => 'jdbc:oracle:thin:@mydatabase:1521:mydb',
 :user => "user",
 :password => "password"

)
ActiveRecord::Base.connection.execute("SELECT * FROM MYTABLE")  

The error I'm getting: C:/Program Files/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.2/lib/active_record/connection_adapters/jdbc_adapter.rb:326:in `initialize': The driver encountered an error: java.sql.SQLException: invalid arguments in call (RuntimeError)

Suggestions?

+1  A: 

The post below implies that you should use :username instead of :user in your connection call:

http://www.ruby-forum.com/topic/143105

as well as the thread of this posting:

http://osdir.com/ml/lang.jruby.user/2007-05/msg00182.html

Dougman
A: 

I think Dougman is correct. My JRuby code is Rails-based, so I can't verify your 'requires', but my database.yml uses "username":

test:

adapter: jdbc

driver: oracle.jdbc.driver.OracleDriver

url: jdbc:oracle:thin:@mydatabase:1521:mydb

username: login_name

password: password

paulbonner