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" } )