DB2 10.5 for Linux, UNIX, and Windows

Verifying the IBM_DB Ruby driver installation with the interactive Ruby shell

To verify the IBM_DB Ruby driver installation, use the interactive Ruby shell (irb) to connect to the database and issue a query.

Procedure

To verify the Ruby driver installation with the interactive Ruby shell, run the listed commands:
C:\>irb
irb(main):001:0> require 'mswin32/ibm_db' 
#If you are using Linux based platform issue require 'ibm_db')
=>true
irb(main):002:0> conn = IBM_DB.connect 'devdb','username','password'  
=> #<IBM_DB::Connection:0x2dddf40>
#Here ‘devdb’ is the database cataloged in client’s
#database directory or db entry in the db2dsdriver.cfg file.
#To connect to a remote database you
#will need to specify all the necessary attributes like
#hostname, port etc as follows.
#IBM_DB.connect('DRIVER={IBM DB2 ODBC=DRIVER};DATABASE=devdb;HOSTNAME=myhost;
PORT=60000;PROTOCOL=TCPIP;UID=uname;PWD=password;','','')
irb(main):003:0> stmt = IBM_DB.exec conn,'select * from staff'
=> #<IBM_DB::Statement:0x2beaabc>
irb(main):004:0> IBM_DB.fetch_assoc stmt 
#Fetches the first row of the result set