Satya's blog - JRuby on Rails with Sybase

Sep 30 2009 10:39 JRuby on Rails with Sybase

Got Sybase*? Got Rails? You're skewered. But you can do it with JRuby and jTDS. Assuming Ubuntu 9.04, but any deb-based system should do.
*(or MSSQL, or SQLServer, whatever the heck it's called)

Get jruby1.1 (or whatever the latest is). This also might drag in 90+ other dependencies. You don't have a choice. Get libjtds-java. Get the following gems: activerecord-jdbc-adapter jruby-openssl

sudo apt-get install jruby1.1 libjtds-java
sudo jruby -S gem install rails activerecord-jdbc-adapter jruby-openssl 

jruby -S: installs the gems into the jruby system instead of the ruby (or cruby, for C) system.

Start a jrails (my term for JRuby on Rails) app by doing: jruby -S rails jdbctestapp

Edit config/database.yml to read something like:

development:
  adapter: jdbc
  url: jdbc:jtds:sybase://server:4100/;TDS=5.0
  database: mydatabasename
  username: foo
  password: bar
  driver: net.sourceforge.jtds.jdbc.Driver

Assuming you know how to handle the database.yml file. For MSSQL, change 'sybase' to 'sqlserver' and set TDS=8.0 (or remove the TDS thing altogether, including the semi-colon).

And then, the best-kept secret of the internet: Add this line, or similar, to your environment.rb file:

require '/usr/share/java/jtds.jar'

That's right, the full path to the jtds jar file (you can find it with dpkg -L libjtds-java|grep jar).

Tag: rails