收藏本页 | 网站地图 | 投稿指南
 
 
当前位置:首页 >> 学院首页 >> 程序开发 >> JSP >>

用jsp向mysql数据表中插入数据

放大字体  缩小字体  At: 2005-09-18 05:37  By: master8 转载 来源: 互联网
<html><head><title>使用JSP插入记录</title></head>
<body><center>
<%@ page language=\"java\" import=\"java.sql.*\" contentType=\"text/html;charset=iso-8859-1\" %>
<%String driver=\"org.gjt.mm.mysql.Driver\";
String url=\"jdbc:mysql://compaq:3306/jxgl\";
String user=\"songbo\";
String password=\"songbo\";
try {
Class.forName(driver);
}
catch(Exception e) {
out.println(\"无法加载驱动程序!!\"+driver);
e.printStackTrace();
}
try {
Connection con=DriverManager.getConnection(url,user,password);
if(!con.isClosed( ))
out.println(\"数据库连接成功!\");
Statement smt = con.createStatement();
smt.executeUpdate(\"INSERT into teacher(t_no,t_name,t_sex,t_birthday,tech_title)\" + \"values(\'000004\',\'李小蓉\',\'女\',\'1967-06-06\',\'讲师\')\");
out.println(\"记录插入完毕!\");
smt.close();
con.close( );
}
catch(SQLException ee) {
out.println(\"数据库连接失败!\");
}
%>
</center></body></html>
 






         









 
Google
论坛精华  
 
 
  ©2005-2008 站长吧 Master8.NET All Rights Reserved 陕ICP备05010609号