From 6f21f474a76774b88c2c71c1dc68f3cd7d8db1ff Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 29 Sep 2023 13:24:26 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20JdbcTemplate=EC=97=90=EC=84=9C=20Da?= =?UTF-8?q?taAccessException=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springframework/jdbc/core/JdbcTemplate.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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); } }