#!/cs/local/bin/perl use DBI; my $database='dbi:DB2:sample'; my $user=''; my $password=''; my $dbh = DBI->connect($database, $user, $password) or die "Can't connect to $database: $DBI::errstr"; my $sth = $dbh->prepare( q{ SELECT sid, sname FROM sailor } ) or die "Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute or die "Can't execute statement: $DBI::errstr"; print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n"; print "$sth->{NAME}->[0]: $sth->{NAME}->[1]\n"; while (($sid, $sname) = $sth->fetchrow()) { print "$sid: $sname\n"; } # check for problems which may have terminated the fetch early warn $DBI::errstr if $DBI::err; $sth->finish;