[英]NameError: cannot load Java class com.mysql.jdbc.Driver
I'm using JRuby 1.7.2, along with DataMapper, and I'm getting an error I can't find an answer to. 我正在使用JRuby 1.7.2,以及DataMapper,我收到一个错误,我找不到答案。
I'm just testing out DataMapper along with MySQL 5.5 to see if it will run fine when I build around it. 我只是测试DataMapper和MySQL 5.5,看看它是否会在我构建时运行良好。 Here's the file I'm testing: 这是我正在测试的文件:
require "data_mapper"
require "keys"
DataMapper.setup(:default, "mysql://#{$user}:#{$pass}@localhost/test_db")
And when I run this, I get the error: 当我运行这个时,我得到错误:
NameError: cannot load Java class com.mysql.jdbc.Driver
And it points to the DataMapper.setup line. 它指向DataMapper.setup行。
My Gemfile should be alright: 我的Gemfile应该没问题:
source :rubygems
gem "sinatra"
gem "trinidad"
gem "data_mapper"
# do a `sudo apt-get install libmysqlclient-dev` first
gem "dm-mysql-adapter"
gem "jdbc-mysql"
Is there anything I'm missing? 有什么我想念的吗? I have MySQL set up with a user/pass locally already. 我已经在本地设置了用户/传递的MySQL。
I'm using Rails 3.2.9 and to solve the problem I added this to my application.rb 我正在使用Rails 3.2.9并解决了我在application.rb中添加的问题
if defined? JRUBY_VERSION
require 'jdbc/mysql'
Jdbc::MySQL.load_driver
end
actually, the correct answer is to work-around an incompatibility between 5.1.13 and 5.1.22 ! 实际上,正确的答案是解决5.1.13和5.1.22之间的不兼容问题!
jdbc-mysql gem already contains the mysql-connector.jar it just ain't auto-loading anymore : jdbc-mysql gem已经包含了mysql-connector.jar,它只是不再自动加载:
https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-mysql (read the README) https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-mysql (阅读README)
you can also force the driver to auto-load using a Java system property eg from a cmd line : 您还可以使用Java系统属性强制驱动程序自动加载,例如从cmd行:
jruby -J-Darjdbc.mysql.autoload=true -S rake ...
I had the same error when trying to use a mysql database from jruby/rails4. 尝试使用jruby / rails4中的mysql数据库时遇到了同样的错误。 In my case this line was missing from ./Gemfile: 在我的情况下,。/ Gemfile中缺少这一行:
gem 'jdbc-mysql'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.