A.4 python – IBM Data Server DB2 User Manual
Page 278
264
DB2 Deployment Guide
";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-4 shows 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()