activerecord-jdbc-adapter
activerecord-jdbc-adapter copied to clipboard
Mac ARM64 "Error opening connection" with activerecord-jdbcsqlite3-adapter
I built an open-source JRuby 9.3.4.0 app, called Contact Manager, using activerecord-jdbcsqlite3-adapter v61.1 and activerecord v6.1.6, and I get an error every time I run it on a Mac ARM64 only (it works on Mac x86_64, Windows 10 x86_64, and Linux x86_64):
% ./bin/contact_manager
== CreateContacts: migrating =================================================
ActiveRecord::JDBCError: Error opening connection
initialize at arjdbc/jdbc/RubyJdbcConnection.java:532
new at org/jruby/RubyClass.java:895
initialize at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/abstract/core.rb:21
initialize at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/sqlite3/adapter.rb:87
initialize at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/abstract/statement_cache.rb:23
new at org/jruby/RubyClass.java:909
jdbc_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/jdbc/connection_methods.rb:10
sqlite3_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-jdbc-adapter-61.2-java/lib/arjdbc/sqlite3/connection_methods.rb:59
public_send at org/jruby/RubyKernel.java:2003
new_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:882
checkout_new_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:926
try_to_checkout_new_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:905
acquire_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:866
checkout at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:588
connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:428
with_connection at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:459
migrate at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/migration.rb:849
migrate at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/activerecord-6.1.6/lib/active_record/migration.rb:663
<main> at /Users/andymaleh/code/contact_manager/db/migrate.rb:6
each at org/jruby/RubyArray.java:1865
<main> at /Users/andymaleh/code/contact_manager/db/migrate.rb:4
require at org/jruby/RubyKernel.java:1017
<main> at /Users/andymaleh/code/contact_manager/db/db.rb:9
require at org/jruby/RubyKernel.java:1017
<main> at /Users/andymaleh/code/contact_manager/app/contact_manager/model/contact.rb:1
require at org/jruby/RubyKernel.java:1017
<main> at /Users/andymaleh/code/contact_manager/app/contact_manager/model/contact_presenter.rb:1
require at org/jruby/RubyKernel.java:1017
<main> at /Users/andymaleh/code/contact_manager/app/contact_manager/view/app_view.rb:1
require at org/jruby/RubyKernel.java:1017
<main> at /Users/andymaleh/code/contact_manager/app/contact_manager.rb:25
require at org/jruby/RubyKernel.java:1017
require_relative at org/jruby/RubyKernel.java:1045
<main> at /Users/andymaleh/code/contact_manager/app/contact_manager/launch.rb:1
load at org/jruby/RubyKernel.java:1052
launch at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/glimmer-dsl-swt-4.23.1.4/lib/glimmer/launcher.rb:149
launch_application at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/glimmer-dsl-swt-4.23.1.4/lib/glimmer/launcher.rb:179
launch at /Users/andymaleh/.rvm/gems/jruby-9.3.4.0@contact_manager/gems/glimmer-dsl-swt-4.23.1.4/lib/glimmer/launcher.rb:172
<main> at ./bin/contact_manager:12
System details:
% uname -a
Darwin Andys-MacBook-Pro.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101 arm64
JRuby/JDK details:
% jruby -v
jruby 9.3.4.0 (2.6.8) 2022-03-23 eff48c1ebf Java HotSpot(TM) 64-Bit Server VM 17.0.1+12-LTS-39 on 17.0.1+12-LTS-39 +jit [arm64-darwin]
SQLite details:
% sqlite3 -version
3.37.0 2021-12-09 01:34:53 9ff244ce0739f8ee52a3e9671adb4ee54c83c640b02e3f9d185fd2f9a179aapl
In any case, you can replicate the error for yourself on a Mac M1 Chip ARM64 machine by following these instructions: https://github.com/AndyObtiva/contact_manager#option-3-clone-project-locally
This is the current db code:
require 'active_record'
require 'jdbc/sqlite3'
Jdbc::SQLite3.load_driver
require 'activerecord-jdbcsqlite3-adapter' if defined? JRUBY_VERSION
@connection = ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: File.join(Dir.home, 'db/contact_manager.sqlite3')
)
require 'db/migrate'
You can check out all the project files at GitHub if needed: https://github.com/AndyObtiva/contact_manager
By the way, I plan to blog about using activerecord-jdbcsqlite3-adapter sometime soon, and I was hoping it would work on Mac ARM64 machines in addition to the other platforms mentioned above.
I look forward to your help in the meantime.
Cheers,
Andy Maleh
I installed Contact Manager using "Option 3: Clone Project Locally", JRuby 9.3.4.0, Windows 7 Professional SP 1 x86_64, and it works fine. This does seem to be an ARM64 issue.
According to https://stackoverflow.com/questions/70048681/java-sql-sqlexception-error-opening-connection, M1 support was added in 3.32.3.3 version of sqlite-jdbc, but this gem bundles 3.28.0, so it needs to be upgraded I guess.
@kares @enebo Ahem, sqlite not working on M1 is pretty poor form...
We need to get the updted sqlite driver gem released. I copied in the latest jar to make my local env work, but not having this gem updated is pretty ugly.
I released an update based on master yesterday. It is not the latest sqlite driver, though, so we should probably consider another update.