⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 update_2.jsp

📁 本系统由6个模块组成。用户登陆
💻 JSP
字号:

<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.sql.*" %>
<HTML>
<BODY  > 
<FONT size=3>
       
   <%!
     boolean query(String number) //查询是否有学号是number 的学生
     {
       Connection con=null;
       Statement sql=null;
       ResultSet rs=null;
      
       try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e) {}

       try{
            con=DriverManager.getConnection("jdbc:odbc:test");
            sql=con.createStatement();
            String condition="SELECT * FROM students where number = "+ "'"+number+"'" ;
            rs=sql.executeQuery(condition);

            int num=0;
            while(rs.next()) num++ ;
            con.close();

            if(num>0) 
               return  true;
            else
               return  false ;
           }
        catch(SQLException e)  
           { return  false; }
      }

    
    String update(String number,float newMath,float newEnglish,float newPhysics)
    {  
      if(query(number))  
        {
          Connection con=null;
          Statement sql=null;
          ResultSet rs=null;
       

          try{
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             }
          catch(ClassNotFoundException e)
             {}

          try{
                con=DriverManager.getConnection("jdbc:odbc:test");
                sql=con.createStatement();
                String condition1=
                "UPDATE students SET math = "+newMath+" WHERE number ="+"'"+number+"'" ;

                String condition2=
                "UPDATE students SET english = "+newEnglish+" WHERE number="+"'"+number+"'" ;

                String condition3=
                "UPDATE students SET phics = "+newPhysics+" WHERE number="+"'"+number+"'" ;

                //执行更新操作
                sql.executeUpdate(condition1);
                sql.executeUpdate(condition2);
                sql.executeUpdate(condition3);
                con.close();
                return  "修改成功";
             }
          catch(SQLException e)
             {  return  "修改失败"  ;}

        }
      else
        { return "没有这个学号" ;}
    }

  %>

  <% //获取提交的学号
     String number=request.getParameter("number");
     number=number.trim();
     if(number==null)
       {
          number="";
       }
     byte b[]=number.getBytes("ISO-8859-1");
     number=new String(b);

     //获取提交的新的数学成绩
     String newMath=request.getParameter("math");
     if(newMath==null)
       {
         newMath="0";
       }
     float  math=Float.parseFloat(newMath);

     //获取提交的新的英语成绩
     String newEnglish=request.getParameter("english");
     if(newEnglish==null)
       {
         newEnglish="0";
       }
      float  english=Float.parseFloat(newEnglish);

      //获取提交的新的物理成绩
      String newPhysics=request.getParameter("physics");
      if(newPhysics==null)
        {
          newPhysics="0";
        }
      float  physics=Float.parseFloat(newPhysics);

  %>
    
  <%

      String   del=update(number, math,english, physics);

      if(del.equals("修改成功"))
         session.setAttribute("xiugai", "修改成功");
      else
         if(del.equals("修改失败"))
             session.setAttribute("xiugai","修改失败");
         else 
             session.setAttribute("xiugai","没有这个学号");

      response.sendRedirect("update_1.jsp");

  %>

</FONT>
</BODY>
</HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -