SQL Server对数据进行删除,把页面的信息从数据库删除。
<table border=1px style="width:500px;height:200px;text-align:center;margin: 0 auto"> <tr style="background:red"> <td>编号</td> <td>书名</td> <td>价格</td> <td>喜爱度</td> <td>作者</td> <td>删除</td> <td>修改</td> </tr> <% //引用连接数据库方法 sqlServer sq=new sqlServer(); //得到数据库连接 Connection con = sq.getConnection(); //编写sql语句 String sql="select * from Dog"; //得到数据库对象操作 Statement st=con.createStatement(); // 得到查询的结果 ResultSet rs = st.executeQuery(sql); while(rs.next()){ %> <tr> <td> <%out.print(rs.getInt(1) + "\t"); %></td> <td> <%out.print(rs.getString(2) + "\t"); %></td> <td> <%out.print(rs.getInt(3) + "\t"); %></td> <td> <%out.print(rs.getInt(4)+"%" + "\t"); %></td> <td> <%out.println(rs.getString(5)+ "\t"); %></td> <td> <a href="Delect.jsp?id=<%out.print(rs.getInt(1) + "\t"); %>">删除</a></td> <td> <a href="Update.jsp?id=<%out.print(rs.getInt(1) + "\t"); %>">修改</a></td> </tr><% } //释放资源 sq.ShiFang(rs,st,con); %> </table>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="jdbc.sqlServer"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.PreparedStatement"%> <% String id = request.getParameter("id"); id = new String(id.getBytes("ISO-8859-1"),"utf-8"); //引用连接数据库方法 sqlServer sq=new sqlServer(); //得到数据库连接 Connection con = sq.getConnection(); //编写sql语句 String sql="delete from Dog where id=" + id + ""; //得到数据库操作对象 PreparedStatement st =con.prepareStatement(sql); // 得到查询的结果 if(st.executeUpdate()>0){ %> <script type="text/javascript"> alert("删除成功"); location="showLog.jsp"; </script> <% }else{ %> <script type="text/javascript"> alert("删除失败"); location="showLog.jsp"; </script> <% } %>
时间: 2024-10-09 17:39:33