Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Two ways to build Apache Derby database applications in JRuby

Fuse the power of Ruby with Derby

Robert Thornton (ret1@acm.org), Java Consultant, Daugherty Business Solutions
Robert Thornton has been developing in the Java language for six years and is currently a consultant for Daugherty Business Solutions. He works as a developer and architect on Java EE applications at various clients in the St. Louis, Mo., area. He has a strong focus on object-oriented development and works primarily in the Java and C++ languages.

Summary:  JRuby is an implementation of the Ruby programming language that runs in the Java™ Virtual Machine (JVM). This tutorial demonstrates how to install and configure JRuby to connect to the Apache Derby database. As Ruby and Ruby on Rails become more popular, JRuby becomes an interesting technology to leverage the portability, security, and class libraries of the JVM while using Ruby features like simple syntax and closures. If you're writing a small application that needs a relational database, or you want to be able to ship a database with your product, then the Derby database is an excellent choice for a persistence mechanism. This tutorial shows you two methods of connecting to and building Derby database applications from JRuby.

Date:  30 Jan 2007
Level:  Intermediate PDF:  A4 and Letter (68 KB | 19 pages)Get Adobe® Reader®

Activity:  9377 views
Comments:  

Before you start

About this tutorial

Apache's Derby database is a small, in-memory database that's ideal for use as an embedded database. (A link to a thorough introduction to Derby is listed in the Resources section.)

JRuby is a pure-Java implementation of the Ruby programming language. Ruby is an object-oriented scripting language well suited for purposes as diverse as system-management scripts, rich Internet applications, or desktop applications. JRuby is currently at a 0.9 release (at the time of this writing), so it's getting close to covering all the functionality in the standard C-based Ruby interpreter. There are still limitations you need to be aware of if you put JRuby into production, but it works for most uses. The two lead developers of the JRuby project were recently hired by Sun, so you can look forward to continued momentum on the JRuby project in the future. Because JRuby lives inside the JVM, you can use the Java class library and do things like implement Java interfaces in Ruby.

This tutorial covers some JRuby basics and how to work with Derby. A developerWorks introduction to JRuby, which describes many of the features of JRuby as of 2004 (version 0.7), and other JRuby tutorials are listed in the Resources section.


Objectives

The goal of this tutorial is to show you how to connect to and use the Apache Derby database via the JRuby interpreter. You'll learn how to insert data into and retrieve it from Derby via JRuby. Two methods of interacting with Derby are presented:

  1. Using JDBC via Ruby within JRuby
  2. Using Ruby's ActiveRecord library (via the ActiveRecord-JDBC library), which has been developed as a part of Ruby on Rails, but can be used stand-alone for Object-Relational Mapping (ORM)

Prerequisites

This tutorial is written for developers who are familiar with Java code and JDBC. Experience with Ruby isn't necessary, but exposure to a scripting language (Perl, Python, Ruby, and so on) will make the syntax easier to follow. You don't need any specific integrated development environment (IDE) or tool knowledge. Familiarity with a text editor and setting environment variables is required.


System requirements

To run the examples in this tutorial, you must have a system capable of running the JVM. The tutorial assumes that your Java environment is successfully configured, so download and install the JVM before continuing with this tutorial.

At this time, you need to be able to run Subversion from the command line to complete the ActiveRecord portion of the tutorial. Download a Subversion client (see the Resources section for links) before continuing with this tutorial if you wish to perform the ActiveRecord examples.

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Information Management, Java technology
ArticleID=193144
TutorialTitle=Two ways to build Apache Derby database applications in JRuby
publish-date=01302007
author1-email=ret1@acm.org
author1-email-cc=ruterbo@us.ibm.com

Next steps from IBM

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.