新闻发布系统
ps = con.prepareStatement("delete from messages where Id=?");
ps.setString(1, id);
if(ps.executeUpdate()==1){ b = true; }
} catch (SQLException e) { e.printStackTrace(); }finally{
DBConnector.free(rs, null, con); }
return b; }
3.6 用户管理 3.6.1 添加用户
public boolean addUser(String username,String password){ boolean b = false; try {
con = DBConnector.getConnection(); ps = con.prepareStatement("insert into admin(name,password) values(?,?)"); ps.setString(1, username); ps.setString(2, password); if(ps.executeUpdate()==1){ b = true; }
} catch (SQLException e) { e.printStackTrace(); }finally{
DBConnector.free(rs, ps, con); }
return b; }
3.6.2 删除用户
public boolean delUser(String userid){ boolean b = false; try {
con = DBConnector.getConnection();
ps = con.prepareStatement("delete from admin where Id=?");
ps.setString(1, userid);