jsp数据库操作之删除

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/JY_WD/article/details/101125551

代码

书接上文,与select.jsp相接。

delete.jsp:

<%--
  Created by IntelliJ IDEA.
  User: 长风
  Date: 2019/9/21
  Time: 19:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<html>
<head>
    <title>数据删除</title>
</head>
<body>
<%!
    public static final String DBDRIVER="com.mysql.cj.jdbc.Driver";
    public static final String DBURL="jdbc:mysql://localhost:3306/webstore?&useSSL=false&serverTimezone=UTC";
    public static final String DBUSER="root";
    public static final String DBPASS="123456";
%>
    <%
    Connection conn=null;
    PreparedStatement pst=null;
    int rs=0;
    String id=request.getParameter("id");
%>

    <%
   try{
	  Class.forName(DBDRIVER);
	  conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
	  String sql_delete="delete from user_table where id="+id+"";
	  //获取要删除的此id的数据库信息
	  pst=conn.prepareStatement(sql_delete);
	  rs=pst.executeUpdate();
	  if(rs!=0){
		  out.println("删除成功");
%>
<jsp:forward page="select.jsp">
    <jsp:param name="ids" value="id"/>
</jsp:forward>
<%
        }
    }
    catch(Exception e){
        out.println(e);
    }

%>
</body>
</html>

运行结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/JY_WD/article/details/101125551