我有一個工作代碼,在您調用removeUser方法時將用戶從數據庫中刪除。 :從數據庫中刪除現有用戶JDBC Oracle
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()); }
}
但是,我需要確保用戶存在之前,我刪除他,否則打印該用戶不存在。這如何實現?
http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html – SJuan76