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 @@ -23,36 +23,36 @@ public JdbcTemplate(final DataSource dataSource) {
this.dataSource = dataSource;
}

public void update(final String sql, final Object... parameters) {
public void update(final String sql, final Object... conditions) {
try (
final Connection connection = getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(sql)
) {
log.debug("query : {}", sql);
for (int i = 1; i <= parameters.length; i++) {
preparedStatement.setObject(i, parameters[i - 1]);
for (int i = 1; i <= conditions.length; i++) {
preparedStatement.setObject(i, conditions[i - 1]);
}
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new DataAccessException(e);
}
}

public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMapper, final Object condition) {
public <T> Optional<T> queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... conditions) {
try (
final Connection connection = getConnection();
final PreparedStatement preparedStatement = connection.prepareStatement(sql)
) {
preparedStatement.setObject(1, condition);
final ResultSet resultSet = preparedStatement.executeQuery();
log.debug("query : {}", sql);
for (int i = 1; i <= conditions.length; i++) {
preparedStatement.setObject(i, conditions[i - 1]);
}
final ResultSet resultSet = preparedStatement.executeQuery();

if (resultSet.next()) {
final T result = rowMapper.mapRow(resultSet, resultSet.getRow());
resultSet.close();
return Optional.ofNullable(result);
}
resultSet.close();
return Optional.empty();
} catch (SQLException e) {
throw new DataAccessException(e);
Expand Down
5 changes: 0 additions & 5 deletions jdbc/src/test/java/nextstep/jdbc/JdbcTemplateTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.springframework.jdbc.core;

import org.junit.jupiter.api.BeforeEach;

import static org.junit.jupiter.api.Assertions.*;

class JdbcTemplateTest {

private JdbcTemplate jdbcTemplate;

@BeforeEach
void setUp() {

}
wonyongChoi05 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading