beautypg.com

3 creating a sample perl application – IBM Data Server DB2 User Manual

Page 216

background image

202

DB2 Deployment Guide

Installation procedure for Windows

If you are using ActiveState Perl distribution (version 5.8 or greater) on Windows,
you can install DBI with the help of ppm:

ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-DB2.ppd

After it is successfully installed, you can check the documentation and a sample
application through perldoc:

perldoc DBD::DB2

If you are using some other Perl distribution on Windows, then the installation
process is manual. Download the and uncompress DBD::DB2 source from:

http://www.cpan.org/authors/id/I/IB/IBMTORDB2/DBD-DB2-1.1.tar.gz

After you uncompress the compressed file into a directory, you can issue
installation commands shown in Example 4-40 on page 201. Issue the same
commands to install DBD::DB2.

4.7.3 Creating a sample Perl application

We create a simple Perl application to demonstrate the application deployment.
This sample application named itso_perlapp.pl reads the connectivity information
from command line and uses that to connect to a database. The database can be
both local or remote. If the connection fails, we get an explanatory error
message. If the connection succeeds, the application shows the success
message. The complete code is shown in A.5, “Perl” on page 265 and is
available for download. For the download instructions, refer to Appendix B,
“Additional material” on page 267.

To run the application, create a directory and save the application as
itso_perlapp.pl. Run the application as shown in Example 4-42. The example
demonstrates a successful connection to a remote database with uncatalog
connection. You can test it against a local database too.

Example 4-42 A successful connection using itso_perlapp.pl

itsouser@ubuntu:~/redbook$ perl itso_perlapp.pl mensa 50001 test db2inst1
password
Trying to establish connection...
Connection successful.
Closing connection...
Connection closed.

Note: You can uninstall DBD::DB2 by issuing the following command:

ppm uninstall DBD::DB2