四. 下面用perl程序来插入若干记录并做查询.
use dbi;
#连接数据库mydata
my $dbh = dbi->connect(’dbi:mysql:mydata’) or die "无法连接数据库: " . dbi->errstr;
print "插入若干记录n";
my $sth = $dbh->prepare(q{
insert into address (id, name,email,telephone) values (?, ?, ?, ?)
}) });
print "输入记录,回车结束:";
while ($inputdata =<>) {
chop $inputdata;
last unless($inputdata);
my ($id, $name,$email, $tel) = split( /,/, $inputdata);
$sth->execute($id, $name, $email,$tel)
}
# $dbh->commit;
print "下面根据输入的名字打印出email地址和电话n";
my $sth = $dbh->prepare(’select * from address where name=?’)
or die $dbh->errstr;
print "请输入姓名,回车结束:";
while ($inputname =<>) {
my @data;
chomp $inputname;
last unless($inputname);
$sth->execute($inputname) or die "错误: " . $sth->errstr;
while (@data = $sth->fetchrow_array()) {
print "email:$data[2]t telephone:$data[3]n";
}
}
#断开连接
$dbh->disconnect;
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器