Skip to content

Commit

Permalink
delete message by id dao method
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 30, 2024
1 parent e17a19e commit 673c27b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/DAO/MessageDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,27 @@ public Message getMessageById(int message_id) {
}
return null;
}

public Message deleteMessageById(int message_id) {
Message message = getMessageById(message_id);
if (message != null) {
try {
Connection conn = ConnectionUtil.getConnection();
String sql = "DELETE FROM message WHERE message_id = ?";
PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

ps.setInt(1, message_id);

int deletedEntity = ps.executeUpdate();

if (deletedEntity > 0) {
return message;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}

}

0 comments on commit 673c27b

Please sign in to comment.