Using Database Servers With JRuby
See Also
How you access the database server from a JRuby on Rails project
depends on whether you are using the MySQL database server.
Accessing the MySQL Database Server With JRuby
If you are using the MySQL database server in your JRuby project,
you have two choices:
- Use the MySQL database adapter.
Because the pure Ruby MySQL driver works in JRuby, you can
use the the MySQL database adapter as you would in a native Ruby application.
- Access the database by using JDBC as described in the following section.
Accessing Other Database Servers With JRuby
You can use JDBC to access the supported database servers,
such as MySQL, PostgreSQL, Oracle, HSQLDB, and Java DB (also known as Derby).
To use a JDBC connection, you must obtain a JDBC 3.0 driver for your
database server. The JDBC driver must be a pure Java driver. The MySQL
and PostgreSQL drivers are bundled with the IDE. At the time of
this writing, ActiveRecord-JDBC does not work with the JDBC driver
for Sqlite.
To access the database by using JDBC:
- When you create the project, select Access Database Using JDBC
in the New Ruby on Rails Application Wizard:
Database Configuration pane.
This selection causes the IDE to add to the
environment.rb class an
entry similar to the following code.
if defined?(JRUBY_VERSION)
require 'rubygems'
gem 'activerecord-jdbc-adapter'
require 'jdbc_adapter'
end
- After you create the project, right-click the project's node
in the Projects window and choose Properties from the pop-up menu. Complete
the following steps in the Project Properties dialog box to add
the JAR files to the project's classpath. Note that for the MySQL
and Postgresql database server, the IDE completes these steps for you.
The IDE also does these steps for you if you configure database
access using a registered
IDE connection
in the New Ruby on Rails Application Wizard:
Database Configuration pane.
- Select Java in the Categories list.
- Click Add Jar/Folder.
- Navigate to and select the JAR file for the
database server's JDBC driver.
- Click Open.
- Click OK to close the Project Properties dialog box.
- See Also
- Working With NetBeans Ruby
- New Ruby on Rails Application Wizard: Name and Location
- Database Configuration
Legal Notices