1 Reply Latest reply on May 23, 2013 9:37 PM by Ankur Srivastava

    Connect Oracle DB and pass values from Rhoconnect to Rhodes app

      Hi All,


      I am newbie in RhoMobile. I am trying to connect oracle 10g database and want to pass value from Rhoconnect to Rhodes application.


      I learned somewhere that, Oci8 gem can be used to connect and get data.


      require 'oci8'


      class DBConnect < SourceAdapter

        def initialize(source)


          my_array = []

          conn = OCI8.new('hr', '123456', 'jdbc:oracle:thin:@')

          conn.select("SELECT * from E", "my_array")





      I have following doubts:

      1.How to include/install/get oci8 gem in code?

      2. How to connect oracle db?

      3. How to test that data has been fetched?

      4. How to pass value from RhoConnect to rhodes app?

      5. How to populate the fetched data?


      I know its foolish to ask all thses in one..

      Please help me out.


      Thanks in Advance

        • Re: Connect Oracle DB and pass values from Rhoconnect to Rhodes app
          Jeffrey Cookle

          I am using the OCI8 with RhoConnect for demo purposes.  I am new to RhoConnect as well, but here is what we did.

          • Create a new RhoConnect Project in RhoStudio. 
          • Add a Source Adapter to it(this is all in the documentation)
          • In your project, find the Gemfile and open it up.   Add this to the bottom of the file

          gem 'ruby-oci8'


          • Goto a command line and navigate to your project, type "bundle install" and that will install the oci8 gem for you to use
        • Go into your source adapter you created and in the initialize you can put the following in there(modify for the info to what you are connecting to)
        • @conn = OCI8.new('hr', '123456', 'jdbc:oracle:thin:@')


          • In the query section of the code, you can use the connection to run your select statement

          @cursor = @conn.parse("SELECT * from E")


          You can then parse through the cursor you created and add the values to the @result for RhoConnect




          def query(params=nil)



          cursor = @conn.parse("SELECT * from E")









               while rv = cursor.fetch


                    key = rv[0]

                    puts "QUERY"


                    puts "#{rv[0]}"

                 # col1 below should be replaced with how you want your client app to use the data.

                    row= {

                    'col1' => rv[0]}








          To test it modify the spec in the rhoconnect application for your model(under the spec folder) make sure this is setup in the spec file.  This will setup a test for you to try the connection. 

          it "should process TestTable query" do

               test_query.size.should > 0

               query_errors.should == {}



          From the command line of your project, you can run rhoconnect redis_start and then rhoconnect spec   This will run the test for RhoConnect.


          I would suggest reviewing the documentation on setting up a RhoMobile application, create a model with the same name as you did in RhoConnect for the source adapter and then enable synching.  This will get your data down there. To add the create, update, and delete steps of this, you will need to define the sql code in your rhoconnect source adapter.


          good luck.

          1 of 1 people found this helpful