#!C:\Perl\bin\perl -w
use DBI;
print "Hello \n";
# Open a connection
# my $dbh = DBI->connect("dbi:DB2:sample", "DB2ADMIN", "db2admin", {RaiseError => 1});
# use VALUES to retrieve value from special register
# my $stmt = "Values CURRENT DATE";
# my $sth = $dbh->prepare($stmt);
# $sth->execute();
# associate variables with output columns...
# my $col1;
# $sth->bind_col(1,\$col1);
# while ($sth->fetch) { print "Today is: $col1\n"; }
# $sth->finish();
# $dbh->disconnect();
my $dbh=DBI->connect("dbi:DB2:Meiyl","wawe","ondemand");
my $stmt = "select * from swimpool";
my $sth = $dbh->prepare($stmt);
$sth->execute();
my $col1;
my $col2;
my $col3;
my $col4;
my $col5;
my $col6;
my $col7;
my $col8;
my $Volume;
$sth->bind_columns(\$col1,\$col2,\$col3,\$col4,\$col5,\$col6,\$col7,\$col8);
while ($sth->fetch) {
chomp($col6);
# print "$col1,$col2,$col3,$col4,$col5,$col6,$col7,$col8\n";
if ($col6 =~ /o/)
{
# print "hahahah\n";
$Volume=$col3*$col4*$col5*1000;
print "$col2:\n Volume of Water is :$Volume. \n";
}
else
{
$Volume=$col3*$col4*(($col7+$col8)/2)*1000;
print "$col2:\n Volume of Water is :$Volume. \n";
}
}
$sth->finish();
$dbh->disconnect();
阅读(1206) | 评论(0) | 转发(0) |