Digital Sanctum

software development, technology and other square topics

Connecting to Oracle from Rails

with 2 comments

Since there are several variations of docs on this (some of which are out of date) I figured I'd document this.

  1. Download and install the Ruby interface from http://rubyforge.org/projects/ruby-oci8/
  2. Then, in your config/database.yml file, you should have something like this:
CODE:
  1. development:
  2.    adapter: oracle
  3.    database: <your-sid-here>
  4.    host: //<your-host-here>:<your-port-here>
  5.    username: <your-username-here>
  6.    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:
  1. common: &shared
  2.    adapter: jdbc
  3.    driver: oracle.jdbc.driver.OracleDriver
  4.    url: jdbc:oracle:thin:@<your-host-here>:<your-port-here>:<your-sid-here>
  5.    username: <your-username-here>
  6.    password: <your-password-here>
  7.  
  8. # oracle (JDBC)
  9. development:
  10.    <<: *shared

Written by Shane

August 1st, 2007 at 2:23 pm

2 Responses to 'Connecting to Oracle from Rails'

Subscribe to comments with RSS or TrackBack to 'Connecting to Oracle from Rails'.

  1. 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

  2. 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

Leave a Reply