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:

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:

  1. 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
    
  2. 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.

    1. Select Java in the Categories list.
    2. Click Add Jar/Folder.
    3. Navigate to and select the JAR file for the database server's JDBC driver.
    4. Click Open.
    5. 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