DBの作成をしてみます(MySQL)

  • せっかくなので、jdbc_adapterを用いて接続してみます。

config/database.ymlは次のような感じに

development:
  adapter: jdbc
  driver: com.mysql.jdbc.Driver
  url: jdbc:mysql://localhost/shoplet
  encoding: utf8
  username: root
  • モデルを作成してmigrate
bash-3.2$ jruby -S rake db:migrate
(in /Users/kuro/jruby/sample/shoplet)
rake aborted!
The driver encountered an error: cannot load Java class com.mysql.jdbc.Driver
  • 調べてみるとまずmysql-connectorがなかったのでインストールしました
  • そしてCLASSPATH(java実行時に見に行くパス)に追加しました。
CLASSPATH=$CLASSPATH:/Users/kuro/jruby/source/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar
export CLASSPATH
  • そしてもう一回実行
bash-3.2$ jruby -S rake db:migrate
(in /Users/kuro/jruby/sample/shoplet)
JdbcAdapterInternalService:122:in `set_connection': java.lang.NoSuchMethodError: org.jruby.runtime.builtin.IRubyObject.setInstanceVariable(Ljava/lang/String
;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject;
        from JdbcAdapterInternalServiceCallback$set_connection_FS1:-1:in `call'
        from org.jruby.runtime.callback.FastInvocationCallback:55:in `execute'
        from org.jruby.internal.runtime.methods.SimpleCallbackMethod:67:in `call'
        from org.jruby.internal.runtime.methods.DynamicMethod:242:in `call'
        from org.jruby.internal.runtime.methods.DynamicMethod:151:in `call'
        from org.jruby.runtime.CallSite$InlineCachingCallSite:156:in `cacheAndCall'
                                   .
                                   .
                                   .
                                   .
                                   .
  • のようなエラー。