删除数据使用的SQL语句为delete语句,如果删除图书id为1的图书信息,其SQL语句为:

delete from book where id=1

在实际开发中删除数据通常使用PreparedStatement对象进行操作。

实例代码:

(1)index.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>查看所有图书</title>
 8 </head>
 9 <body>
10     <a href="FindServlet">查看所有图书</a>
11 </body>
12 </html>

(2)book_list.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@ page import="com.java.Book" %>
 4 <%@ page import="java.util.ArrayList" %>
 5 <%@ page import="java.util.List" %>
 6 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 7 <html>
 8 <head>
 9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10 <title>删除数据</title>
11 <style>
12     td{
13         font-size:12px;
14     }
15     h2{
16         margin:2px;
17     }
18 </style>
19 <script type="text/javascript">
20     function check(form){
21         with(form){
22             if(bookCount.value == ""){
23                 alert("请输入更新数量!");
24                 return false;
25             }
26             if(isNaN(bookCount.value)){
27                 alert("格式错误!");
28                 return false;
29             }
30             return true;
31         }
32     }
33 </script>
34 </head>
35 <body>
36     <div style="text-align:center;">
37         <table align="center" width="500px" border="1" height="170px" bordercolor="white" bgcolor="black" cellpadding="1">
38             <tr bgcolor="white">
39                 <td align="center" colspan="6">
40                     <h2>所有图书信息 </h2>
41                 </td>
42             </tr>
43             <tr align="center" bgcolor="#e1ffc1">
44                 <td><b>ID</b></td>
45                 <td><b>图书名称</b></td>
46                 <td><b>价格</b></td>
47                 <td><b>作者</b></td>
48                 <td><b>修改数量</b></td>
49                 <td><b>删除</b></td>
50             </tr>
51             <%
52                 List<Book> list = (List<Book>)request.getAttribute("list");
53                 if(list ==null || list.size() < 1){
54                     out.print("数据为空");
55                 }else{
56                     for(Book book:list){
57                         
58                     
59                 
60             %>
61             <tr align="center" bgcolor="white">
62                 <td><%= book.getId() %></td>
63                 <td><%= book.getName() %></td>
64                 <td><%= book.getPrice() %></td>
65                 <td><%= book.getBookCount() %></td>
66                 <td><%= book.getAuthor() %></td>
67                 <td>
68                     <a href="DeleteServlet?id=<%=book.getId()%>">删除</a>
69                 </td>
70             </tr>
71             <%
72                     }
73                 }
74             %>
75          </table>
76     </div>
77 </body>
78 </html>
查看代码

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
相关资源
相似解决方案