jsp數據庫操作之刪除


代碼

書接上文,與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>

運行結果

在這里插入圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM