Hi Everyone, Im looking for a way to connect to a DB2 database using the latest versions of Jruby, Rails and ActiveRecord, I already used:
activerecord-jdbc-adapter - not longer supports DB2
ibm_db - works fine, but only works on ruby and i need jruby
db2_odbc_adapter - issues when I try to install it, no support or comment section on github.
I need something that helps ActiveRecord to connect to DB2, for the connection pool and all the benefits of use it
So there is some options?
Thanks in advance
Hi Leo,
Yes, there are some options you can try. One option is to use ActiveRecord’s JDBC adapter since you are using JRuby. The “activerecord-jdbcmssql-adapter” gem supports DB2 since it is a JDBC adapter.
You can include it in your Gemfile as:
gem 'activerecord-jdbc-adapter'
Run bundle install
in your terminal to install it.
After that, you would need to set up your database.yml
similar to this:
development:
adapter: jdbc
url: jdbc:db2://localhost:50000/database_name
username: your_username
password: your_password
Please replace localhost
, 50000
, database_name
, your_username
, and your_password
with your actual DB2 database details.
I hope this helps you! Let me know if you have any issues.
Best,
Bobby the Bot
Hi I get that this is a bot but it dont responds my question, I already tried and talked with the devs of the gem on a issue created on Github, please reffer to the next search, i cant paste the link here:
db2 is not (yet) fully supported #7817
Only errors I get are
OUTPUT
#NOTE: ActiveRecord 4.2 with adapter: db2 is not (yet) fully supported by AR-JDBC, please consider helping us out. FrozenError: can’t modify frozen Hash []= at org/jruby/RubyHash.java:1180
OUTPUT
ArgumentError: wrong number of arguments (given 4, expected 1…3) initialize at /root/.rvm/gems/jruby-9.4.2.0/gems/activerecord-jdbc-adapter-70.0-java/lib/arjdbc/abstract/core.rb:12
More info about the env:
JRuby version 9.4.2.0(3.1.0)
RedHat 8.4(CentOs 8), openjdk version "17.0.5" 2022-10-18 LTS
Gem: activerecord-jdbc-adapter-70.0-java, activerecord (7.0.5)
Two applications, one with only jRuby and other one with ruby on rails
Expected Behavior
Use the gem establish connection using activerecord::base to DB2