Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Sybase ASE 12.5.4 with jTDS drivers with JRuby
    text
    copied!<p><strong>Problem</strong></p> <p>I am trying to build a small ruby script - which will be run using jruby once a day - to connect to a Sybase ASE 12.5.4 database and perform a complex query. </p> <p>Ultimately I intend to do some processing on the data and insert the new data in a MySQL table for use within a rails application.</p> <p><strong>Environment</strong></p> <ul> <li>jruby v1.4.0</li> <li>java v1.6.0_15</li> <li>on Ubuntu Karmic</li> </ul> <p><strong>JRuby Installed Gems</strong></p> <ul> <li>activerecord-jdbc-adapter (0.9.1)</li> <li>activerecord-2.3.4</li> </ul> <p><strong>Jruby Lib Directory</strong></p> <ul> <li>jtds-1.2.5</li> </ul> <p><strong>Query</strong></p> <pre><code>SET rowcount 10 SELECT * FROM TEST_TABLE </code></pre> <p><strong>Code Snippet</strong></p> <pre><code>require 'java' require 'jtds-1.2.5.jar' require 'rubygems' require 'active_record' config = { :username =&gt; 'railstest', :password =&gt; 'railstest', :adapter =&gt; 'jdbc', :dialect =&gt; 'sybase', :host =&gt; 'localhost', :database =&gt; 'railstest', :port =&gt; '5000', :driver =&gt; 'net.sourceforge.jtds.jdbc.Driver', :url =&gt; 'jdbc:jtds:sybase://localhost:5000/railstest' } ActiveRecord::Base.establish_connection(config).connection.execute(-- QUERY --) </code></pre> <p>I can confirm this connects to the DB. Although I am having issues just selecting 10 rows from a database table. </p> <p><strong>Produces</strong></p> <p>For <strong>execute</strong> method:</p> <pre><code>/usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log': ActiveRecord::ActiveRecordError: The executeUpdate method must not return a result set.: SET rowcount 10 SELECT * FROM TEST_TABLE (ActiveRecord::StatementInvalid) from /usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.2/lib/active_record/connection_adapters/jdbc_adapter.rb:559:in `execute' from db-test.rb:21 </code></pre> <p>For <strong>select_rows</strong> method:</p> <pre><code>/usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log': ActiveRecord::ActiveRecordError: The executeUpdate method must not return a result set.: SET rowcount 10 SELECT * FROM TEST_TABLE (ActiveRecord::StatementInvalid) from /usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.2/lib/active_record/connection_adapters/jdbc_adapter.rb:559:in `execute' from /usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.2/lib/active_record/connection_adapters/jdbc_adapter.rb:629:in `select' from /usr/local/bin/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.2/lib/active_record/connection_adapters/jdbc_adapter.rb:550:in `select_rows' from db-test.rb:21 </code></pre> <p>The error states that I should not return a results set but it doesn't matter which method I use, execute, select_rows etc nothing works.</p> <p>One more thing regarding queries. My original query is rather complex, I decalre variables, drop temporary tables and create temporary tables as well as populate and select from them. Using Squirrel SQL I can execute once and gain a result. Using DBI I was unable to do this in one execution, does anyone know if I can just execute the whole thing once or will I have to split it up?</p> <p>Would anyone be able to give me any assistance please? Am I using jTDS properly? Many thanks in advance. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload