Spring-Jdbc 템플릿을 사용할 때 Prepared Statement와 Connection (jt.getDataSource(). getConnection())을 닫아야합니까? 아니면 템플릿 메커니즘에 의해 닫힐까요? 방금 (문자열 SQL 객체 ... 인수)를 .update를를 사용하는 양식을하는 경우 기본적으로Spring-Jdbc 템플릿과 Prepared 문
public void updateRow() throws SQLException {
final int i = 100;
final int y = 2;
PreparedStatementCreator creator = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement updateSales = con.prepareStatement(
"update ignor set ignored_id=? where id=?");
updateSales.setInt(1, i);
updateSales.setInt(2, y);
return updateSales;
}
};
PreparedStatement updateIgnor = creator.createPreparedStatement(jt.getDataSource().getConnection());
int k = updateIgnor.executeUpdate();
System.out.println("rows updated = " + k);
}
쿼리를 한 번만 실행합니까? – SMA
글쎄, 실제 응용 프로그램 에서이 방법은 여러 번 실행할 수 있습니다 ... – andy007