Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1단계 - JDBC 라이브러리 구현하기] 베베(최원용) 미션 제출합니다. #264

Merged
merged 10 commits into from
Sep 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public void update(final String sql, final Object... conditions) {
final PreparedStatement preparedStatement = connection.prepareStatement(sql)
) {
log.debug("query : {}", sql);
for (int i = 1; i <= conditions.length; i++) {
preparedStatement.setObject(i, conditions[i - 1]);
}
setConditions(preparedStatement, conditions);
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new DataAccessException(e);
Expand All @@ -44,9 +42,7 @@ public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMa
final PreparedStatement preparedStatement = connection.prepareStatement(sql)
) {
log.debug("query : {}", sql);
for (int i = 1; i <= conditions.length; i++) {
preparedStatement.setObject(i, conditions[i - 1]);
}
setConditions(preparedStatement, conditions);
final ResultSet resultSet = preparedStatement.executeQuery();

if (resultSet.next()) {
Expand All @@ -66,7 +62,6 @@ public <T> List<T> query(final String sql, final RowMapper<T> rowMapper) {
final ResultSet resultSet = preparedStatement.executeQuery()
) {
log.debug("query : {}", sql);

final List<T> results = new ArrayList<>();
while (resultSet.next()) {
results.add(rowMapper.mapRow(resultSet, resultSet.getRow()));
Expand All @@ -86,4 +81,10 @@ public Connection getConnection() {
}
}

private void setConditions(PreparedStatement preparedStatement, Object[] conditions) throws SQLException {
for (int i = 1; i <= conditions.length; i++) {
preparedStatement.setObject(i, conditions[i - 1]);
}
}
wonyongChoi05 marked this conversation as resolved.
Show resolved Hide resolved

}
Loading