码迷,mamicode.com
首页 > 数据库 > 详细

JSP--TOMCAT-MYSQL web页面删除

时间:2014-05-25 23:44:41      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

deleteStudentjsp.jsp页面代码

bubuko.com,布布扣
<%@ 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>
bubuko.com,布布扣

after_deleteStudent.jsp代码

bubuko.com,布布扣
<%@ 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>
bubuko.com,布布扣

 

JSP--TOMCAT-MYSQL web页面删除,布布扣,bubuko.com

JSP--TOMCAT-MYSQL web页面删除

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/yuhuameng/p/3750146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!