원래 사용한 콜백 makePreparedStatement() 메서드
→ 대응하는 JdbcTemplate 의 콜백:
Before
public void deleteAll() throws SQLException {
this.jdbcTemplate.update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
return con.prepareStatement("delete from users");
}
}
);
}
기존의 JdbcContext.executeSql() 메서드
→ 대응하는 JdbcTemplate 의 메서드 update()
public void deleteAll() throws SQLException {
this.jdbcTemplate.update("delete from users");
}
<aside> 💡
update() 의 파라미터 유형
</aside>
⇒ JdbcTemplate 에서 제공하는 메서드로 변환해보자
public void add(final User user) throws SQLException {
this.jdbcTemplate.update("insert into users(id, name, password) values(?,?,?)", user.getId(), user.getName(), user.getPassword());
}