Connecting to Oracle from Rails
Since there are several variations of docs on this (some of which are out of date) I figured I'd document this.
- Download and install the Ruby interface from http://rubyforge.org/projects/ruby-oci8/
- Then, in your config/database.yml file, you should have something like this:
CODE:
-
development:
-
adapter: oracle
-
database: <your-sid-here>
-
host: //<your-host-here>:<your-port-here>
-
username: <your-username-here>
-
password: <your-password-here>
If you're running Rails with JRuby you should have the Oracle JDBC drivers in the classpath and the entry above will be a little different:
CODE:
-
common: &shared
-
adapter: jdbc
-
driver: oracle.jdbc.driver.OracleDriver
-
url: jdbc:oracle:thin:@<your-host-here>:<your-port-here>:<your-sid-here>
-
username: <your-username-here>
-
password: <your-password-here>
-
-
# oracle (JDBC)
-
development:
-
<<: *shared
I have ActiveRecord on JRuby talking to Oracle except that AR’s find_by_ methods don’t work. Is that a shortcoming of the ActiveRecord-JDBC? Or am I still missing something?
Thanks for the tutorial, and thanks for your help.
Denny
15 Aug 07 at 1:49 pm
I’m at my witts end here I can’t get oracle connection with Jruby no matter how I try to connect to it, i have tried all methods, all I get is this :
chrisr@s231:~/code/workspace/PDFCollater> jruby script/server
=> Booting WEBrick…
NumberFormatException.java:48:in `java.lang.NumberFormatException.forInputString’: java.lang.NumberFormatException: For input string: “?” (NativeException)
from Integer.java:447:in `java.lang.Integer.parseInt’
from RubyYaccLexer.java:1411:in `org.jruby.lexer.yacc.RubyYaccLexer.yylex’
from RubyYaccLexer.java:123:in `org.jruby.lexer.yacc.RubyYaccLexer.advance’
I’d love any help!!
Thanks
Chris
Chris Richards
13 Sep 07 at 11:55 am