发生了无法正确删除 前三行删不了

来源:3-11 删除分类的代码实现

学习中的傅山

2019-07-09 00:07:31

private void delete(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException{
   //接收数据
  Integer cid=Integer.parseInt(request.getParameter("cid")) ;
   System.out.println("cid"+cid);
  //业务层调用数据
   CategoryService categoryService=new CategoryServiceImpl();
   categoryService.delete(cid);
   //页面跳转
   response.sendRedirect(request.getContextPath()+"/CategoryServlet?method=findAll");
}public void delete(Integer cid) {
   Connection conn=null;
   PreparedStatement pstmt=null;
   try {
      //获得连接
       conn=JDBCUtils.getConnection();
       //编写sql
       String sql="delete from category  where cid=?";
       pstmt=conn.prepareStatement(sql);
       pstmt.setInt(1,cid);
       pstmt.executeUpdate();
   } catch (Exception e) {
       e.printStackTrace();
   } finally {
       JDBCUtils.release(pstmt,conn);
   }
}

我看了提问中其他的人的问题也是这个  只有删除其他的才有cid 的获取(不包括前三行)

http://img.mukewang.com/climg/5d236a230001515010230096.jpg

http://img.mukewang.com/climg/5d236a2c00010f5b01460039.jpg

但是代码是和老师的一模一样的  就是前三行无法删除

写回答

1回答

好帮手慕阿满

2019-07-09

同学你好,问一下同学该分类下是否存在具体的商品,如果存在,该分类是不能删除的。如果想删除该分类,需要将该分类下的商品都删除,然后再删除分类。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

0

0 学习 · 8016 问题

查看课程