1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

jruby + ActiveRecord + jdbc + mysql(mariadb)のミニマムサンプル

Last updated at Posted at 2023-03-31

以下サンプルソース

Gemfile
source "https://rubygems.org"

gem 'activerecord'
gem 'activerecord-jdbcmysql-adapter'
sample.rb
require "jdbc/mysql"
require "active_record"

ActiveRecord::Base.establish_connection(
  :adapter  => 'mysql',
  :url => 'jdbc:mysql://localhost:3306',
  :username => 'root',
  :password => '',
  :charset => 'utf8mb4',
  :encoding => 'utf8mb4',
  :collation => 'utf8mb4_general_ci'
)


# p ActiveRecord::Base.connection
pp ActiveRecord::Base.connection.execute("show databases")

実行方法

以下、Windows上での動作確認。PowerShellを前提とする

$ bundle exec jruby .\sample.rb

jrubyは予めインストールされている状態。

動作環境

$ jruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda OpenJDK 64-Bit Server VM 11.0.12+7 on 11.0.12+7 +jit [x86_64-mswin32]

jrubyを入れた時点でbundleコマンドも一緒に入るみたい

$ gcm jruby

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     jruby.exe                                          1.0.0.0    c:\jruby-9.4.2.0\bin\jruby.exe
$ gcm bundle

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     bundle.bat                                         0.0.0.0    c:\jruby-9.4.2.0\bin\bundle.bat
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?