简体   繁体   English

NameError:无法加载Java类com.mysql.jdbc.Driver

[英]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。

This is a common error when running JDBC clients for MySQL . 在为MySQL运行JDBC客户端时,这是一个常见错误。 You need to make sure you have mysql-connector-java-bin.jar on the classpath. 您需要确保在类路径上有mysql-connector-java-bin.jar You can download it from here . 你可以从这里下载。

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.135.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.

相关问题 无法加载驱动程序 class:com.mysql.jdbc.Driver Spring - Cannot load driver class: com.mysql.jdbc.Driver Spring 无法加载 JDBC 驱动程序类 [com.mysql.jdbc.Driver] - Could not load JDBC driver class [com.mysql.jdbc.Driver] MySQL查询原因:SEVERE:无法加载JDBC驱动程序类'com.mysql.jdbc.Driver' - MySQL queries cause: SEVERE: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' 无法加载JDBC驱动程序类'com.mysql.jdbc.Driver'Tomcat 8和Eclipse - Cannot load JDBC driver class 'com.mysql.jdbc.Driver' Tomcat 8 & Eclipse 无法在“ intellij idea”中加载JDBC驱动程序类“ com.mysql.jdbc.Driver” - Cannot load JDBC driver class 'com.mysql.jdbc.Driver' in “intellij idea” java.lang.IllegalStateException: 无法加载 JDBC 驱动程序类 [com.mysql.jdbc.Driver] - java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 无法加载驱动程序 class com.mysql.Z84BEFFD3A0D49636A58CE6080CAA87C7 - Failed to load driver class com.mysql.jdbc.Driver 无法使用Gradle和Spring Boot加载驱动程序类:com.mysql.jdbc.Driver - Cannot load driver class: com.mysql.jdbc.Driver with Gradle and Spring Boot 无法加载驱动程序类:com.mysql.jdbc.Driver Spring Boot - Cannot load driver class: com.mysql.jdbc.Driver Spring Boot Java如何查找类? (尝试加载驱动程序:com.mysql.jdbc.Driver) - Java How To Find Class? (Attempting to load the driver: com.mysql.jdbc.Driver)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM