| 用jsp向mysql数据表中插入数据 |
|
来源:互联网 |
时间:2005-09-18 |
浏览:
相关评论 |
报告错误 |
发布文章
|
【字号:大 | 中 | 小】
【背景色
】
|
|
<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>
|
|
 |
| |
|
|
|
|