Skip to content

Instantly share code, notes, and snippets.

@lukeholder
Created January 11, 2013 06:53
Show Gist options
  • Save lukeholder/4508527 to your computer and use it in GitHub Desktop.
Save lukeholder/4508527 to your computer and use it in GitHub Desktop.
How to connect to Microsoft SQL Server with jruby on Windows using JDBC and Sequel Gem
require "java"
require "rubygems"
require "sequel"
require "sqljdbc4.jar" #this files path may need to be relevate to file location
DB = Sequel.connect(
:adapter => "jdbc",
:url => "jdbc:sqlserver://doric-server5;database=ADCData_Doric;integratedSecurity=true"
# This is using integrated security, might want to pass username and password
# More Info at http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
)
the_table = DB[:the_table_name.identifier]
puts the_table.to_csv
  1. Install jruby (you may also need the package with JRE if is not already on your machine): http://jruby.org/download
  2. Install the sequel gem: gem install sequel
  3. Download the jdbc driver for SQL Server: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774
  4. Copy the sqljdbc4.jar in step 3's download into your apps directory (your app with require this later)
  5. Copy the correct (32 bit or 64 bit) sqljdbc_auth.dll in step 3's download into your windows system32 folder
  6. See demo.rb below for example of use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment