Appendix A. Sample applications 265
# Creating dsn from command line arguments.
dsn = "HOSTNAME=" + argv[0] + \
";PORT=" + argv[1] + \
";DATABASE=" + argv[2] + \
";PROTOCOL=TCPIP" + \
";UID=" + argv[3] + \
";PWD=" + argv[4]
print "Trying to establish connection..."
conn = ibm_db.connect( dsn, "", "" )
print "Is connection active? : ", ibm_db.active(conn)
print "Closing connection..."
ibm_db.close(conn)
print "Connection closed."
if __name__ == "__main__":
main(sys.argv[1:])
A.5 Perl

Example A-5 shows the application used to demonstrate the deployment of the

DB2 Perl application.

Example: A-5 Sample Perl application
# A sample perl 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:
# perl itso_perlapp.pl hostname port_number database_name user password
#
use DBI;
# Varifying the number of command line arguments.
if ($#ARGV != 4){
print " ERROR: incorrect command line arguments.\n Use hostname port_number
database_name user_name password\n";
exit 1;
}