admin_subjectadd.jsp
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:2k
源码类别:

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ page import="jinghua.*"%>
  3. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  4. </jsp:useBean>
  5. <%!boolean debug=false;
  6. %>
  7. <%
  8. String subname=""+request.getParameter("subject_name");
  9. String gradenote=""+request.getParameter("grade");
  10. subname=Tools.codestring(subname);
  11. subname=subname.trim();
  12. gradenote=Tools.codestring(gradenote);
  13. gradenote=gradenote.trim();
  14. if(debug){
  15.     out.print("<br>subname="+subname);
  16.     out.print("<br>gradenode="+gradenote);
  17. }
  18. if(subname.equals("") ){
  19.     Tools.showalert("请您输入科目名称",out);
  20.     Tools.goback(out);
  21. }else{
  22.     try{
  23.         Connection con=DBCon.getConnection();
  24.         String sql="select * from subject where name='"+subname.trim()+"' and gradenote='"+gradenote+"'";
  25.         PreparedStatement pstmt=con.prepareStatement(sql);
  26.         ResultSet rs=pstmt.executeQuery();
  27.         if (rs.next()){
  28.             Tools.showalert("该年级的科目信息在数据库中已经存在!",out);
  29.             Tools.goback(out);
  30.             rs.close();
  31.             pstmt.close();
  32.         }else{
  33.             sql="insert into subject(name,gradenote) values('"+subname+"','"+gradenote+"'"+")";
  34.             //Tools.showalert(sql,out);
  35.             rs.close();
  36.             pstmt.close();
  37.             pstmt=con.prepareStatement(sql);
  38.             pstmt.executeUpdate();
  39.             if(debug){
  40.                 out.print("<BR>insert="+sql);
  41.             }
  42.             Tools.showalert("成功添加科目信息!",out);
  43.             response.sendRedirect("admin_subject.jsp");
  44.            //Tools.showJS("window.open('admin_subject.jsp','_self')",out);
  45.         }
  46.     }catch(SQLException se){
  47.         out.println(se.toString());
  48.     }
  49.     finally{
  50.     DBCon.dropConnection();
  51.     }
  52. }
  53. %>