Software engineer, data guy, Open Source enthusiast, New Hampshire resident, husband, father. Fan of guitars, hiking, photography, homebrewing, sarcasm.
JRuby: connect to a MSSQL database via ActiveRecord and create ActiveRecord::Base classes
In this snippet I’ll share some code that allows you to connect to a MSSQL database via ActiveRecord in a JRuby environment. In this code I decided to use the “Microsoft JDBC Driver for SQL Server”. It can be downloaded here. Copy the Java jar (sqljdbc4.jar) into your project space to get started.
Create a gem file to include the ActiveRecord JDBC adapter, file: Gemfile. Execute “bundle install” to install the dependencies.
The following shows some sample code to establish an ActiveRecord connection to MSSQL using the JDBC driver.
Bonus: query the database for a list of tables and dynamically create an ActiveRecord model for each.