JSP--TOMCAT-MYSQL web页面删除

deleteStudentjsp.jsp页面代码

<%@ page language="java" contentType="text/html; charset=GB2312"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title> DELETE STUDENT</title>
</head>
<body>
    <table style="border-right:#89d4f8 1px solid; 
      border-top:#89d4f8 1px solid; 
      border-left:#89d4f8 1px solid"
      cellSpacing=0 cellpadding=70 align=center bgColor=#ffffff border=0>
      <tbody>
          <tr>
            <td height=26>&nbsp;&nbsp;删除学生信息</td>           
          </tr>
          <tr>
             <td height=1 bgColor=#89d4f8> </td>
          </tr>   
      </tbody>
      </table>
       <!-- 以post方式提交数据 -->
      <form name="messages" method="post" action="after_deleteStudent.jsp">
         <table width="50" align="center" border="0">
           <tr>
                  <td height=26>&nbsp;&nbsp;&nbsp;</td>
           </tr>
           <tr>
                  <td width="267">按学号删除: </td>
                  <td><input type="text"name="StuID"></td>
                  
           </tr>
           <TR>
              <td width="67"></td>
              <td><input type="submit"value="删除"></td>
           </TR>
         </table>
      
      </form>
</body>
</html>

after_deleteStudent.jsp代码

<%@ page language="java" 
import="java.util.*" 
import="com.mysql.jdbc.Driver" 
import="java.sql.*" 
contentType="text/html;charset=gb2312" 
pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>after_deleteStudent</title>
</head>
<body>
<%

       Connection conn;
       Statement stat;
       //设置连接的url,其中student是数据库名称
       String url="jdbc:mysql://localhost:3306/student";
       //我使用的是免安装版的mysql,用户:root,密码:zhangweijie
       String userName="root";
       String password="zhangweijie";
       //获取deleteStudentjsp.jsp页面post过来的StuID
        int StuID=Integer.parseInt(request.getParameter("StuID"));
       try{
       //注册JDBC驱动程序
          Class.forName("com.mysql.jdbc.Driver");
       
       }
       catch(ClassNotFoundException ex){
       
           out.println("找不到驱动程序!");
       }
       //打开数据库连接
       
       conn=DriverManager.getConnection(url, userName, password);
       try{
           stat=conn.createStatement();
           //执行删除操作
           int isOK=stat.executeUpdate("delete from Student_Info where StuID="+StuID+"");
           
           if(isOK>0)
           {
              out.println("删除成功!");
           }
       }
       catch(SQLException ex){
             out.println("删除失败!");
       }
       
       finally{
           conn.close();
       }
       
 %>
     
</body>
</html>

 

JSP--TOMCAT-MYSQL web页面删除,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。