";PROTOCOL=TCPIP" << \ ";UID=" << ARGV[3] << \ ";PWD=" << ARGV[4]

puts "Trying to establish connection..." conn = IBM_DB::connect( dsn, "", "" ) if conn

puts "Is connection active? : #{IBM_DB::active(conn)}" puts "Closing connection..."

IBM_DB::close(conn)

puts "Connection closed." else

puts IBM_DB::conn_errormsg()

end

end

A.4 Python

Example A-4shows the application used to demonstrate the deployment of the DB2 Python application.

Example: A-4 Sample Python application

"""A sample python application.

Use this program to test connection to a database.

Database connectivity information is read as command line arguments. Give arguments in the following order:

hostname port_number database_name user password

Run the application as following:

python itso_pyapp.py hostname port_number database_name user password

"""

import sys import ibm_db

def main(argv):

# Varifying the number of command line arguments. if len(argv) != 5:

print " ERROR: incorrect command line arguments.\n Use hostname port_number database_name user_name password\n"

sys.exit()

264DB2 Deployment Guide

Page 278
Image 278
IBM manual Example A-4 Sample Python application, 264 DB2 Deployment Guide