use strict; use DBI; use DBD::DB2; my $db2_user = 'USER'; my $db2_pass = 'PASSWORD'; my $dbh = DBI->connect('dbi:DB2:DB2', $db2_user, $db2_pass, {AutoCommit => 0, RaiseError => 0, PrintError => 1}) or die "Cant connect to DB - $DBI::errstr\n"; my $stmt = "select ID from RULE where key = 123"; my $sth = $dbh->prepare($stmt) or die "Cant prepare ($stmt) - $DBI::errstr\n"; $sth->execute or die "Cant execute ($stmt) - $DBI::errstr\n"; if ($sth->errstr) { die "Failed to execute ($stmt) - ", $sth->errstr(), "\n"; } print "the execute should have failed before here\n"; my $col1; $sth->bind_col(1,\$col1); while ($sth->fetch) { print "id is: $col1\n"; } print "should not get here\n"; $sth->finish() or die "Cant close sth - $DBI::errstr\n"; $dbh->disconnect() or die "Cant disconnect from DB - $DBI::errstr\n";