rails 3.2 with jruby and mysql with rvm in ubuntu

If was trying to migrate one of the app from ruby to jrby to try out the threading benifits.

this wasn't an easy task :D

well the gem dependency did not create a big issue.

the problem came when connecting to mysql with jdbc driver
I had replaced

 gem 'mysql2'

 gem 'activerecord-jdbcmysql-adapter'

in Gemfile

But it refused to load the driver saying :

"The driver encountered an unknown error: cannot load Java class com.mysql.jdbc.Driver'

I searched but Google could not answer me :(

then I started looking into activerecord-jdbsmysl-adapter gem and came upon the the file 

activerecord-jdbc-adapter / activerecord-jdbcmysql-adapter / lib / active_record / connection_adapters /jdbcmysql_adapter.rb 

I just copy pasted the code in a application.rb config with a condition if jruby used just after the bundler code

if defined?(JRUBY_VERSION)
  require 'jdbc/mysql'
  Jdbc::MySQL.load_driver(:require) if Jdbc::MySQL.respond_to?(:load_driver)

and boom it worked...!!!

I don't know why it did not load it even if it was included in Gemfile.

but at last I was able to run the app wit jruby and rails. Woaaahhhh..


  1. thanks mate, solved my problem!

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  3. It was really a nice post and i was really impressed by reading this Ruby on Rails Online Training Hyderabad


Post a Comment

Popular posts from this blog

Difference between rake db:migrate db:reset and db:schema:load

Install Multimedia codec (offline) without internet connection in Ubuntu