diff --git a/jdbc/src/main/java/org/springframework/dao/SizeException.java b/jdbc/src/main/java/org/springframework/dao/SizeException.java new file mode 100644 index 0000000000..f5e8cfa4cd --- /dev/null +++ b/jdbc/src/main/java/org/springframework/dao/SizeException.java @@ -0,0 +1,26 @@ +package org.springframework.dao; + +public class SizeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public SizeException() { + super(); + } + + public SizeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public SizeException(String message, Throwable cause) { + super(message, cause); + } + + public SizeException(String message) { + super(message); + } + + public SizeException(Throwable cause) { + super(cause); + } +} diff --git a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 864b266f0c..50e4510bc0 100644 --- a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -11,6 +11,7 @@ import javax.sql.DataSource; import org.springframework.dao.DataAccessException; +import org.springframework.dao.SizeException; import org.springframework.jdbc.datasource.DataSourceUtils; public class JdbcTemplate { @@ -26,7 +27,7 @@ public JdbcTemplate(final DataSource dataSource) { public T queryForObject(final String sql, final RowMapper rowMapper, final Object... params) { List results = query(sql, rowMapper, params); if (results.size() > 1) { - throw new DataAccessException("too many result. expected 1 but was " + results.size()); + throw new SizeException("too many result. expected 1 but was " + results.size()); } if (results.isEmpty()) { throw new DataAccessException("no result"); @@ -37,7 +38,7 @@ public T queryForObject(final String sql, final RowMapper rowMapper, fina public T queryForObject(final Connection connection, final String sql, final RowMapper rowMapper, final Object... params) { List results = query(connection, sql, rowMapper, params); if (results.size() > 1) { - throw new DataAccessException("too many result. expected 1 but was " + results.size()); + throw new SizeException("too many result. expected 1 but was " + results.size()); } if (results.isEmpty()) { throw new DataAccessException("no result");