Using Ruby to connect to DB2 and extract data to a CSV

Well the young boys keep raving about Ruby. I still think Python has a lot more library support via eggs because it has been around longer. Anyhow I gave Ruby a crack for this trivial task and, yes, the same as Python, it does’nt take too much code to automate a painful manual task.

This little script, runs on windows. It will connect to a remote IBM DB2 database, execute a query, then output the result set to a CSV file. You will need some prerequisites before you can do this. Before you continue for this you will need a DB2 client installed, although not the full DB2 client is needed you can download and install the appropriate IBM Data Server Driver for ODBC/JDBC and CLI from here IBM DataServer drivers. If you already have DB2 client software installed then dont worry about this.

Continue reading