Using Ruby to access data on a DB2 database on an AS/400 or iSeries system

By Alvin J. Alexander, devdaily.com

Here's a quick look at a Ruby program I created to read data from a table (file) on an AS/400 (iSeries) DB2 database. First, here's the demo Ruby program, where I changed a few names to protect the innocent:

require 'odbc'
require 'dbi'

dbh = DBI.connect('DBI:ODBC:MY_AS400', 'MY_USER', 'MY_PASS')
sth = dbh.prepare('select count(*) from my_table')
sth.execute

# Print out each row
while row=sth.fetch do
  p row
end

sth.finish
dbh.disconnect

As you can see I hit the As/400 (iSeries) DB2 database using an ODBC driver. The ODBC driver is the big trick here. I hadn't considered using Ruby to access data on the iSeries until one day when I noticed an Excel add-in named "Client Access Data Transfer", and a few options under the Data menu named "Transfer Data to iSeries" and "Transfer Data from iSeries". Once I saw those I began licking my chops, and was able to get this Ruby demo program running very quickly.

Sorry, I'm out of writing time for today, so I'll have to leave this off here for now. Suffice it to say that if you have software named "IBM iSeries Access for Windows" installed on your system, you can probably configure an ODBC driver that you can use with Ruby to access data on the iSeries.


devdaily logo