Using MySQL with JRuby

Posted by chetan on February 23, 2010 in development

For some reason, I had a relatively hard time finding this info all in one spot, so here it is:

Using MySQL with JRuby is actually pretty easy (and no annoying arch issues on OS X! :-)

Install GEMs (DBI, JDBC driver, DBI adapter):

$ jgem install dbi jdbc-mysql dbd-jdbc

Then use it!

require 'dbi'
require 'jdbc/mysql'
dbh = DBI.connect('dbi:jdbc:mysql://localhost:3306/test', 'root', '', 
                  { "driver" => "com.mysql.jdbc.Driver" } )
Comments

Leave a response

  1. Karthik Fri, 04 Nov 2016 03:24:05 EDT

    The above script is not working for me. I’m using Jruby 1.7.26 version

    Error is :: Unable to load driver ‘jdbc’ (underlying error: wrong constant name jdbc) (DBI::InterfaceError)

Comments