insert.jsp~9~
上传用户: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("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 Info(stu_id, name, sex, " +
  30.  "age,dept, ruxdate,tel,address) Values ('" +
  31.  ISOtoGb2312.convert( request.getParameter("stu_id")) + "','" +
  32.  ISOtoGb2312.convert( request.getParameter("name")) + "','" +
  33.  ISOtoGb2312.convert( request.getParameter("sex")) +  "','" +
  34.  ISOtoGb2312.convert( request.getParameter("age")) + "','" +
  35.                           ISOtoGb2312.convert( request.getParameter("dept")) + "','" +
  36.                           ISOtoGb2312.convert( request.getParameter("ruxdate")) + "','" +
  37.                           ISOtoGb2312.convert( request.getParameter("tel")) + "','" +
  38.         ISOtoGb2312.convert( request.getParameter("address")) + "')";
  39. stmt.executeUpdate(strSQL);
  40. ResultSet rs; //建立ResultSet(结果集)对象
  41. rs = stmt.executeQuery("SELECT * FROM Info"); //执行SQL语句
  42. rs.close(); //关闭ResultSet对象
  43. stmt.close(); //关闭Statement对象
  44. con.close();  //关闭Connection对象
  45. %>
  46.         <script language="JavaScript">
  47.          alert("添加成功");
  48.          location.href='add.jsp'
  49.                  </script>
  50. <CENTER>
  51. </CENTER><center>
  52. <h3><a href="add.jsp">返回</a></h3></center>
  53. </body>
  54. </html>