対話式 Ruby シェルによる IBM_DB Ruby ドライバー・インストールの検証

IBM_DB Ruby ドライバー・インストールを検証するには、対話式 Ruby シェル (irb) を使用してデータベースに接続し、照会を発行します。

プロシージャー

対話式 Ruby シェルを使用して Ruby ドライバー・インストールを検証するには、以下にリストされているコマンドを実行します。
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