JRuby's ActiveRecord adapter using JDBC.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
activerecord-jdbcderby-adapter
activerecord-jdbch2-adapter
activerecord-jdbchsqldb-adapter
activerecord-jdbcmssql-adapter
activerecord-jdbcmysql-adapter
activerecord-jdbcpostgresql-adapter
activerecord-jdbcsqlite3-adapter
bench
jdbc-derby make sure *gem.homepage* is "easier" to locate for some Jul 14, 2014
jdbc-firebird make sure *gem.homepage* is "easier" to locate for some Jul 14, 2014
jdbc-h2
jdbc-hsqldb
jdbc-jtds
jdbc-mariadb
jdbc-mysql
jdbc-postgres
jdbc-sqlite3 match (released) jdbc-sqlite3 3.20.1 gem version on this branch Nov 9, 2017
lib
rails_generators
rakelib
src/java/arjdbc Merge branch '51-stable' into 52-stable Sep 4, 2018
test
.gitignore
.travis.yml
.yardopts
CONTRIBUTING.md
Gemfile
History.md
LICENSE.txt
README.md
RUNNING_TESTS.md
Rakefile
Rakefile.jdbc
activerecord-jdbc-adapter.gemspec
pom.xml

README.md

ActiveRecord JDBC Adapter

Gem Version

ActiveRecord-JDBC-Adapter (AR-JDBC) is the main database adapter for Rails' ActiveRecord component that can be used with JRuby. ActiveRecord-JDBC-Adapter provides full or nearly full support for: MySQL, PostgreSQL, SQLite3. In the near future there are plans to add support MSSQL. Unless we get more contributions we will not be going beyond these four adapters. Note that the amount of work needed to get another adapter is not huge but the amount of testing required to make sure that adapter continues to work is not something we can do with the resources we currently have.

For Oracle database users you are encouraged to use https://github.com/rsim/oracle-enhanced.

Version 50.x supports Rails version 5.0.x and it lives on branch 50-stable. Version 51.x supports Rails version 5.1.x and is currently on master until its first release. The minimum version of JRuby for 50+ is JRuby 9.1.x and JRuby 9.1+ requires Java 7 or newer (we recommend Java 8 at minimum).

Using ActiveRecord JDBC

Inside Rails

To use AR-JDBC with JRuby on Rails:

  1. Choose the adapter you wish to gem install. The following pre-packaged adapters are available:
  • MySQL (activerecord-jdbcmysql-adapter)
  • PostgreSQL (activerecord-jdbcpostgresql-adapter)
  • SQLite3 (activerecord-jdbcsqlite3-adapter)
  1. If you're generating a new Rails application, use the following command:

    jruby -S rails new sweetapp

  2. Configure your database.yml in the normal Rails style:

development:
  adapter: mysql2 # or mysql
  database: blog_development
  username: blog
  password: 1234

For JNDI data sources, you may simply specify the JNDI location as follows, it's recommended to use the same adapter: setting as one would configure when using "bare" (JDBC) connections e.g. :

production:
  adapter: postgresql
  jndi: jdbc/PostgreDS

NOTE: any other settings such as database:, username:, properties: make no difference since everything is already configured on the JNDI DataSource end.

JDBC driver specific properties might be set if you use an URL to specify the DB or preferably using the properties: syntax:

production:
  adapter: mysql
  username: blog
  password: blog
  url: "jdbc:mysql://localhost:3306/blog?profileSQL=true"
  properties: # specific to com.mysql.jdbc.Driver
    socketTimeout:  60000
    connectTimeout: 60000

Standalone with ActiveRecord

Once the setup is made (see below) you can establish a JDBC connection like this (e.g. for activerecord-jdbcderby-adapter):

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: 'db/my-database'
)

Using Bundler

Proceed as with Rails; specify ActiveRecord in your Bundle along with the chosen JDBC adapter(s), this time sample Gemfile for MySQL:

gem 'activerecord', '~> 5.0.6'
gem 'activerecord-jdbcmysql-adapter', :platform => :jruby

When you require 'bundler/setup' everything will be set up for you as expected.

Without Bundler

Install the needed gems with JRuby, for example:

gem install activerecord -v "~> 5.0.6"
gem install activerecord-jdbc-adapter --ignore-dependencies

If you wish to use the adapter for a specific database, you can install it directly and the (jdbc-) driver gem (dependency) will be installed as well:

jruby -S gem install activerecord-jdbcmysql-adapter

Your program should include:

require 'active_record'
require 'activerecord-jdbc-adapter' if defined? JRUBY_VERSION

Source

The source for activerecord-jdbc-adapter is available using git:

git clone git://github.com/jruby/activerecord-jdbc-adapter.git

Please note that the project manages multiple gems from a single repository, if you're using Bundler >= 1.2 it should be able to locate all gemspecs from the git repository. Sample Gemfile for running with (MySQL) master:

gem 'activerecord-jdbc-adapter', :github => 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter', :github => 'jruby/activerecord-jdbc-adapter'

Getting Involved

Please read our CONTRIBUTING & RUNNING_TESTS guides for starters. You can always help us by maintaining AR-JDBC's wiki.

Feedback

Please report bugs at our issue tracker. If you're not sure if something's a bug, feel free to pre-report it on the mailing lists or ask on the #JRuby IRC channel on http://freenode.net/ (try web-chat).

Authors

This project was originally written by Nick Sieger and Ola Bini with lots of help from the JRuby community. Polished 3.x compatibility and 4.x support (for AR-JDBC >= 1.3.0) was managed by Karol Bucek among others.

License

ActiveRecord-JDBC-Adapter is open-source released under the BSD/MIT license. See LICENSE.txt included with the distribution for details.

Open-source driver gems within AR-JDBC's sources are licensed under the same license the database's drivers are licensed. See each driver gem's LICENSE.txt.