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 c7db41651d..e3b5c3c9b7 100644 --- a/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -2,6 +2,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.dao.DataAccessException; import javax.sql.DataSource; import java.sql.Connection; @@ -25,7 +26,7 @@ public JdbcTemplate(final DataSource dataSource) { public void execute(final String sql, final Object... params) { try ( final Connection conn = dataSource.getConnection(); - final PreparedStatement pstmt = conn.prepareStatement(sql); + final PreparedStatement pstmt = conn.prepareStatement(sql) ) { log.debug("query : {}", sql); @@ -34,14 +35,14 @@ public void execute(final String sql, final Object... params) { pstmt.executeUpdate(); } catch (final SQLException e) { log.error(e.getMessage(), e); - throw new RuntimeException(e); + throw new DataAccessException(e); } } public List query(final String sql, RowMapper rowMapper) { try ( final Connection conn = dataSource.getConnection(); - final PreparedStatement pstmt = conn.prepareStatement(sql); + final PreparedStatement pstmt = conn.prepareStatement(sql) ) { log.debug("query : {}", sql); @@ -56,14 +57,14 @@ public List query(final String sql, RowMapper rowMapper) { return results; } catch (final SQLException e) { log.error(e.getMessage(), e); - throw new RuntimeException(e); + throw new DataAccessException(e); } } public Optional queryForObject(final String sql, RowMapper rowMapper, final Object... params) { try ( final Connection conn = dataSource.getConnection(); - final PreparedStatement pstmt = conn.prepareStatement(sql); + final PreparedStatement pstmt = conn.prepareStatement(sql) ) { log.debug("query : {}", sql); @@ -79,7 +80,7 @@ public Optional queryForObject(final String sql, RowMapper rowMapper, return Optional.empty(); } catch (final SQLException e) { log.error(e.getMessage(), e); - throw new RuntimeException(e); + throw new DataAccessException(e); } }