将嵌入式 Derby 与 JRuby on Rails 结合使用
尝试将 JRuby 1.2.0 和 Rails 2.3.2 与嵌入式 Derby 数据库一起使用。 我已将 derbytools.jar
和 derby.jar
复制到 $RUBY_HOME/lib
,但 rake db:migrate
仍然给出:
The driver encountered an error:
cannot load Java class org.apache.derby.jdbc.ClientDriver
Aaaand...我凭直觉找到了答案。 因此,我会将其发布在这里,以防其他人遇到与我相同的问题。
我在网上找到的几乎所有文档都具有以下 Derby 的 database.yml
配置:
development:
adapter: jdbc
driver: org.apache.derby.jdbc.ClientDriver
url: jdbc:derby:[db];create=true
username: xxx
password: xxx
这可能适用于客户端/服务器设置,但对于嵌入式 Derby 设置,您需要这样:
development:
adapter: jdbc
driver: org.apache.derby.jdbc.EmbeddedDriver
url: jdbc:derby:[db];create=true
username: xxx
password: xxx
注意“EmbeddedDriver” ',而不是'ClientDriver'。
Attempting to use JRuby 1.2.0 and Rails 2.3.2 with an embedded Derby database. I've copied derbytools.jar
and derby.jar
to $RUBY_HOME/lib
, yet rake db:migrate
still gives:
The driver encountered an error:
cannot load Java class org.apache.derby.jdbc.ClientDriver
Aaaand... I played a hunch and figured it out. So, I'll post this here in case somebody else runs into the same problem I did.
Almost all the documentation I found online has the following database.yml
configuration for Derby:
development:
adapter: jdbc
driver: org.apache.derby.jdbc.ClientDriver
url: jdbc:derby:[db];create=true
username: xxx
password: xxx
This probably works fine for a client/server setup, but for an embedded Derby setup, you need this:
development:
adapter: jdbc
driver: org.apache.derby.jdbc.EmbeddedDriver
url: jdbc:derby:[db];create=true
username: xxx
password: xxx
Note the 'EmbeddedDriver', and not 'ClientDriver'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我要回答,因为我讨厌在我的个人资料中看到那个红色块。
当您使用嵌入式 derby 时,ActiveRecord-JDBC 中还有一个微妙的错误 - 如果您不给它用户名和密码,则什么都不起作用。 我已经找到了这个错误的原因,并且正在努力提交补丁,但是如果您遇到与我相同的问题,请告诉我,我将在此处发布代码。
Going to answer, because I hate seeing that red block in my profile.
There's also a subtle bug in ActiveRecord-JDBC when you use embedded derby -- if you don't give it a username and a password, nothing works. I've tracked down the cause of this bug, and am working on submitting a patch, but if you run into the same problem I did, let me know, and I'll post the code here.
奇怪的是,在我的 ubuntu 9.04 机器上,它对我来说工作得很好:
我只使用标准的 ubuntu 软件包,我的数据库配置是:
Strange it worked fine for me , on my ubuntu 9.04 box :
i m using only the standard ubuntu packages and my DB configuration is :
ClientDriver 位于 derbyclient.jar 中
The ClientDriver is in derbyclient.jar
根据 Don 的回答,我在没有用户名/密码的情况下使用 ClientDriver 时遇到此错误:
驱动程序遇到错误:java.sql.SQLNonTransientConnectionException:密码长度 (0) 超出 1 到 255 的范围。< /code>
在database.yml中设置用户名/密码解决了这个问题!
Further to Don's answer, I was getting this error when using the ClientDriver without a username/password:
The driver encountered an error: java.sql.SQLNonTransientConnectionException: Password length (0) is outside the range of 1 to 255.
Setting username/password in database.yml fixed the problem!