I am trying to update a resource in DB via @PutMapping (org.springframework.web.bind.annotation.PutMapping)
by calling a stored procedure via (java.sql.PreparedStatement.executeUpdate())
. This step is working absolutely fine and I am getting below integer response from DB:
- 1 - 1 row updated
- 0 - No row updated
I want to send the response back to the user on the basis of integer returned from the DB, for that I am returning ResponseEntity<UpdateResponseVO>
from the rest controller, where UpdateResponseVO is normal POJO class:
public class UpdateResponseVO {
private String responseCode;
private String message;
}
I am framing the ResponseEntity on the basis of below condition:
UpdateResponseVO apiResponse = new UpdateResponseVO();
if (row > 0) {
apiResponse.setResponseCode("200");
apiResponse.setMessage("Updated Successfully.");
return new ResponseEntity<UpdateResponseVO>(apiResponse, HttpStatus.OK);
}
else {
apiResponse.setResponseCode(???);
apiResponse.setMessage("No row updated.");
return new ResponseEntity<UpdateResponseVO>(apiResponse, ???);
}
Now my question is what should be my response code when 0 row gets updated (this condition arises when we are not aware of the current value to be updated in the DB and we give the same value. For e.g in DB already student name is "abc" and we want to update it to "abc" again. Hence row updated will be 0) and what HttpStatus I should send along with the ResponseEntity.