这条容易到有点不想写,还是有始有终把。
点击了list页面的删除后创建
public class DelServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int subjectId = Integer.parseInt(request.getParameter("subjectId"));
// System.out.println(subjectId);
SubjectDao dao = new SubjectDao();
dao.delById(subjectId);
response.sendRedirect(request.getContextPath()+"/ListServlet");
}
}
public void delById(int subjectId) {
try(Connection conn = DBUtil.getConn()) {
String sql = "delete from subject where subjectid=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, subjectId);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}