[jruby-user] using pg and mysql gems on jruby-head?

61 views
Skip to first unread message

Dan F

unread,
Jun 22, 2012, 3:18:38 PM6/22/12
to us...@jruby.codehaus.org
I filed https://github.com/jruby/jruby/issues/214. enebo said, "Try jruby-1.7.0.pre1". Okay. I am looking to see if jruby is faster for my CPU-bound long-running process (15 minutes for the short version).

I installed Java 7. I did "rvm install jruby-head". I tried "bundle" to install my gems, and it barfed on "mysql" and "pg" (at least) because they are native extensions, even after I threw caution to the wind and put "cext.enabled=true" in my .jrubyrc. However, I need to access postgres and mysql. Google revealed sometimes there are alternative gems for jruby, also suggested plans for supporting native extensions in newer versions of jruby, but I can't find details on either.

What is the state of this? Can I install pg and mysql gems somehow, must I abandon attempts at jruby, or is there hidden option c? Please don't ask me to significantly rewrite my source tree (e.g., change require statements), especially if it leaves it ruby-incompatible.

Thanks for your attention.

Dan F

unread,
Jun 22, 2012, 3:20:23 PM6/22/12
to us...@jruby.codehaus.org
Oh, the detailed error message:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/me/.rvm/rubies/jruby-head/bin/jruby extconf.rb 
/Users/me/.rvm/rubies/jruby-head/lib/ruby/shared/mkmf.rb:14: Use RbConfig instead of obsolete and deprecated Config.
mkmf.rb can't find header files for ruby at /Users/me/.rvm/rubies/jruby-head/lib/native/include/ruby/ruby.h

Alex Tambellini

unread,
Jun 22, 2012, 3:23:52 PM6/22/12
to jruby...@googlegroups.com, us...@jruby.codehaus.org
You need to use the jdbc adapters when using jruby:

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

Roger Pack

unread,
Jun 22, 2012, 3:26:11 PM6/22/12
to us...@jruby.codehaus.org
I typically use "pure java" gems or wrap JDBC myself.
For rails it doesn't require "much" code change:
https://github.com/jruby/activerecord-jdbc-adapter
YMMV

--
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Dan Frankowski

unread,
Jun 22, 2012, 3:41:54 PM6/22/12
to us...@jruby.codehaus.org
Thanks for your suggestions.

I am using the 'sequel' gem. says: https://github.com/jruby/activerecord-jdbc-adapter "Legacy configuration: If you use one of the convenience ‘activerecord-jdbcXXX-adapter’ adapters, you can still put a ‘jdbc’ prefix in front of the database adapter name as below."

$ gem install activerecord-jdbcpostgresql-adapter
Fetching: activerecord-jdbc-adapter-1.2.2.gem (100%)
Fetching: jdbc-postgres-9.1.901.gem (100%)
Fetching: activerecord-jdbcpostgresql-adapter-1.2.2.gem (100%)
Successfully installed activerecord-jdbc-adapter-1.2.2
Successfully installed jdbc-postgres-9.1.901
Successfully installed activerecord-jdbcpostgresql-adapter-1.2.2
3 gems installed


Tried adapter of "jdbcpostgresql". I get:

Sequel::AdapterNotFound: LoadError: no such file to load -- sequel/adapters/jdbcpostgresql
  chained_4_rescue_line_25 at /Users/me/.rvm/gems/jruby-head/gems/sequel-3.36.1/lib/sequel/database/connecting.rb:27
...

Looked in dir:

$ ls /Users/me/.rvm/gems/jruby-head/gems/sequel-3.36.1/lib/sequel/adapters/jdbc/postgresql.rb 
/Users/me/.rvm/gems/jruby-head/gems/sequel-3.36.1/lib/sequel/adapters/jdbc/postgresql.rb


So how do I choose the right adapter for sequel?

Thanks for your attention.

Rohit Namjoshi

unread,
Jun 22, 2012, 7:38:12 PM6/22/12
to us...@jruby.codehaus.org
Hi Dan

You should be asking this question on the Sequel Google group https://groups.google.com/forum/?fromgroups#!forum/sequel-talk

Since you are using Sequel and not AR you need to install the jdbc-postgres gem, I would uninstall activerecord-jdbcpostgresql-adapter first. The uri should be of the form jdbc:postgresql://<host>/<database>. More details here http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html

Rohit

Dan Frankowski

unread,
Jun 27, 2012, 12:59:42 PM6/27/12
to us...@jruby.codehaus.org
Although technically you are correct (this is about using sequel), it is a barrier to using jruby. I would think if the jruby community wants to support users, it would be good to have a ready answer to what seems a common question to me.

Dan Frankowski

unread,
Jun 27, 2012, 1:01:02 PM6/27/12
to us...@jruby.codehaus.org
Also, I am not using a URI. As stated, I am using an adapter, i.e. Sequel.connect with :host, :database, :user, :port, :adapter parameters.

Rohit Namjoshi

unread,
Jun 27, 2012, 6:16:47 PM6/27/12
to us...@jruby.codehaus.org
The advantage of using a uri is that you can append any connection specific options supported by the postgres jdbc driver to the uri string.

Sequel.connect(:adapter  => 'jdbc',
      :username => 'xxx',
      :password => 'xxx',
      :uri      => 'jdbc:postgresql://localhost;database=xyz')
Reply all
Reply to author
Forward
0 new messages