Here's a quick look at a "Ruby DB2" program I created to read data from a DB2 database table on an AS/400 (iSeries) DB2 database.
My Ruby DB2 ODBC example program
First, here's the example Ruby program that accesses the As400 DB2 database, with a few names changed 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
Ruby As400 DB2 example - discussion
As you can see I hit the As/400 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.