基本步骤和增加操作差不多
1.定义userDao接口中
//.删除用户public boolean delet(int uid);
2.实现userDao接口中的方法
public boolean delet(int uid) {
System.out.println("在dao层执行delete方法");
boolean flag=false;
try {
con=db.getCon();
if(con==null){
System.out.println("dao中数据库连接不成功");
return flag;
}
String sql="delete from tb_users where uid=?";
pstmt=(PreparedStatement) con.prepareStatement(sql);
pstmt.setInt(1, uid);
int state=pstmt.executeUpdate();
if(state>0){
System.out.println("dao中删除成功");
flag=true;
}
pstmt.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
showuser.jsp中:
<a href="/demo0313/UserServelt?action=delete&uid=<%=uu.getUid()%>">删除</a>