Ahmet Karakaya
Ahmet Karakaya

Reputation: 10139

Force throw an exception if affected rowcount is zero

Is there are special method of Spring Framework to throw an exception in case affected rowcount is zero while UPDATE operation is performed?

I know the following methods:

org.springframework.dao.EmptyResultDataAccessException is used at SELECT operation.

int rowCount = this.getJdbcTemplate().update("update");
if (rowCount == 0) {
  throw new Exception(...);
}

Upvotes: 3

Views: 1010

Answers (1)

hmrojas.p
hmrojas.p

Reputation: 582

Someday I was looking similar something, I found this:

http://docs.spring.io/spring/docs/4.1.0.BUILD-SNAPSHOT/javadoc-api/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.html

You can define a given number of rows to update, if your SQL update overcome this number, a exception is thrown. I think you can define zero as incorrect number.

I hope this information helps you.

Good luck.

Upvotes: 1

Related Questions