Advertisement
Guest User

Untitled

a guest
May 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1.   @Override
  2.   public void delete(Local local) throws SQLException {
  3.     final String req =
  4.       "DELETE FROM api_locaux WHERE id_local=?";
  5.     PreparedStatement stmt = connection.prepareStatement(req);
  6.     stmt.setInt(1, local.getIdLocal());
  7.     try {
  8.       int result = stmt.executeUpdate();
  9.       // Si aucune ligne n'a été mise à jour, on n'a pas trouvé le local.
  10.       if(result == 0) {
  11.         throw new SQLException(
  12.           "Identifiant de local non trouvé, aucune ligne effacée"
  13.         );
  14.       }
  15.     }
  16.     catch (SQLIntegrityConstraintViolationException icve) {
  17.       throw new SQLException("Ce record ne peut pas être supprimé car il est lié à d'autres records");
  18.     }
  19.     finally {
  20.       stmt.close();
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement