Jruby On Rails which is the best database adapter, mysql2 or jdbcmysql?

I am working on JRuby on Rails Application with JRuby-1.6.7 and Rails 3.2.2

I have a mysql database . I was trying to use a database adapter.

I have used mysql2 and jdbcmysql . Both work.

But if I don't access the application for some time and after that when I access it it gives an error like this

undefined method `explain' for #<ActiveRecord::ConnectionAdapters::MySQLAdapter:0x1139ba37>

      

Which database adapter should I prefer? Will my application work after deployment?

+3


source to share


3 answers


I got the same error before, but after some effort, I defined the adapter in my gem file as below and everything works fine until today:

if defined?(JRUBY_VERSION)
  gem 'activerecord-jdbc-adapter', '=1.1.3'
  gem 'jdbc-mysql', :require=>false
  gem 'activerecord-jdbcmysql-adapter', '=1.1.3'
else
  gem 'mysql2'
end

      



hope this helps.

+4


source


I tried @Vik's solution to downgrade activerecord-jdbc but it didn't work for me - caused more problems.

I found this in the activitecord-jdbc github issue list:

https://github.com/jruby/activerecord-jdbc-adapter/issues/159



It's basically a monkey - fixing a new method of explanation to do nothing - until its extension supports it.

HTH, Chris

0


source


since AR-JDBC 1.2.x and esp. when using 1.3.x it is fine to keep the config as is for JRuby eg.

development:
  adapter: mysql2
  database: blog_development
  username: blog
production: 
  adapter: mysql2
  database: blog
  pool: 50
# ... etc

      

than in Gemfile , just limit gems like mysql2 for MRI and jdbc-mysql for JRuby:

source 'https://rubygems.org'

gem 'rails', '~> 3.2.17'

gem 'mysql2', :platform => :mri
gem 'activerecord-jdbc-adapter'
gem 'jdbc-mysql', :platform => :jruby

# ...

      

ps this q seems to generate a lot of traffic for the repo, thus adding the actual answer.

0


source