3. 템플릿
템플릿
1 다시보는 초난감 DAO
2 변하는 것과 변하지 않는 것
public interface StatementStrategy { PreparedStatement makePreparedStatement(Connection connection) throws SQLException; }public class DeleteAllStatement implements StatementStrategy { @Override public PreparedStatement makePreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("delete from test"); return ps; } }public class AddStatement implements StatementStrategy { private User user; public AddStatement(User user) { this.user = user; } @Override public PreparedStatement makePreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("insert into test values (?,?,?)"); ps.setString(1, user.getId()); ps.setString(2, user.getName()); ps.setString(3, user.getPassword()); return ps; } }
3 JDBC 전략 패턴의 최적화
4 컨텍스트와 DI
6 스프링의 JdbcTemplate
Last updated