add.jsp~46~
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

VBScript

  1. <%@ page contentType="text/html; charset=GBK" %>
  2. <%@ page import = "java.sql.*"%>
  3. <%@ page language = "java"%>
  4. <%@ page import = "proj112.ISOtoGb2312"%>
  5. <html>
  6. <head>
  7. <title>
  8. 添加数据
  9. </title>
  10. </head>
  11. <body text="#808080" link="#FF99CC" vlink="#FF8080" alink="#FF99CC" topmargin="0" leftmargin="0"><style>
  12. <!--
  13. BODY {SCROLLBAR-FACE-COLOR: #FFFFFF; SCROLLBAR-HIGHLIGHT-COLOR: #FFFFFF; SCROLLBAR-SHADOW-COLOR: #FFFFFF; SCROLLBAR-3DLIGHT-COLOR: #FFFFFF; SCROLLBAR-ARROW-COLOR:  #FFAAAA; SCROLLBAR-TRACK-COLOR: #FFFFFF; SCROLLBAR-DARKSHADOW-COLOR: #FFFFFF; }
  14. -->
  15. </style>
  16. <%
  17.   String idvalue = request.getParameter("stu_name").trim();
  18.   String capvlu = null;
  19.  %>
  20. <br><br>
  21. <font color="8282DC" size="5"><center>
  22. </font></center><br><br>
  23. <%
  24. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别
  25. Connection con = DriverManager.getConnection("jdbc:odbc:dsn112"); //建立数据库链接
  26. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
  27. ResultSet.CONCUR_READ_ONLY);
  28. String strSQL;
  29. strSQL = "INSERT INTO student(stu_name, stu_id, stu_password, " +
  30.  "sex,dept, mz,zzmm) Values ('" +
  31.  ISOtoGb2312.convert( request.getParameter("stu_name")) + "','" +
  32.  ISOtoGb2312.convert( request.getParameter("stu_id")) + "','" +
  33.  ISOtoGb2312.convert( request.getParameter("stu_password")) +  "','" +
  34.  ISOtoGb2312.convert( request.getParameter("sex")) + "','" +
  35.                           ISOtoGb2312.convert( request.getParameter("dept")) + "','" +
  36.                           ISOtoGb2312.convert( request.getParameter("mz")) + "','" +
  37.                          ISOtoGb2312.convert( request.getParameter("zzmm")) + "')";
  38. stmt.executeUpdate(strSQL);
  39. ResultSet rs; //建立ResultSet(结果集)对象
  40. rs = stmt.executeQuery("SELECT * FROM student"); //执行SQL语句
  41. rs.close(); //关闭ResultSet对象
  42. stmt.close(); //关闭Statement对象
  43. con.close();  //关闭Connection对象
  44. %>
  45.         <script language="JavaScript">
  46.          alert("添加成功");
  47.          location.href='std.jsp'
  48.                  </script>
  49. <CENTER>
  50. </CENTER><center>
  51. <h3><a href="std.jsp">返回</a></h3></center>
  52. </body>
  53. </html>