我这里有一个工作代码,当您调用 removeUser 方法时,它会从数据库中删除用户。:
public void removeUser(String username)
{
try {
pstmnt = conn.prepareStatement("DELETE FROM user_info WHERE username = ?");
pstmnt.setString(1, username);
pstmnt.executeUpdate();
pstmnt = conn.prepareStatement("DELETE FROM users WHERE username = ?");
pstmnt.setString(1, username);
pstmnt.executeUpdate();
//pstmnt.executeBatch();
System.out.println("Removed User :" + username);
} catch (SQLException e) {System.out.println("Error: " + e.getMessage()); }
}
但是,我需要在删除用户之前确保用户存在,否则打印用户不存在。如何实现?