Hi all,

Just want to know if there is an alternative to these error "trapping" that
am using for the following code:

#!/usr/bin/perl

use DBI;

$dbh = DBI->connect('dbi:Oracle:host=localhost;sid=test1;port=1521',
'test1_user', 'test1_password');
if ( defined($dbh) ) {        # Checking for a successful connect >..
   print "No error ... okay to run execute and prepare ... \n";
   my $sth = $dbh->prepare("alter session set nls_date_format = 'DD-MON-YYYY
HH24:MI:SS'") || warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";
   my $sth = $dbh->prepare("select 'Today is ' || sysdate from dual") ||
warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";
   while (my ($sysdate) = $sth->fetchrow_array()) {
      print $sysdate, "\n";
   }
   $sth->finish();
} else {
   print "Errors from DBI->conncect !!! Cannot run execute and prepare ...
\n";
}


......
......


$dbh = DBI->connect('dbi:Oracle:host=localhost;sid=test1;port=1521',
'test2_user', 'test2_password');
if ( defined($dbh) ) {        # Checking for a successful connect >..
   print "No error ... okay to run execute and prepare ... \n";
   my $sth = $dbh->prepare("alter session set nls_date_format = 'DD-MON-YYYY
HH24:MI:SS'") || warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";
   my $sth = $dbh->prepare("select 'Today is ' || sysdate from dual") ||
warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";
   while (my ($sysdate) = $sth->fetchrow_array()) {
      print $sysdate, "\n";
   }
   $sth->finish();
} else {
   print "Errors from DBI->conncect !!! Cannot run execute and prepare ...
\n";
}

BTW, is there other alternative to the following line of codes besides using
warn on each lines?

   my $sth = $dbh->prepare("alter session set nls_date_format = 'DD-MON-YYYY
HH24:MI:SS'") || warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";
   my $sth = $dbh->prepare("select 'Today is ' || sysdate from dual") ||
warn "Connection error !!! \n";
   $sth->execute() || warn "Connection error !!! \n";


Any feedback will be very much appreciated. Thanks in advance

Reply via email to