Нужно ли закрывать готовое заявление и соединение (jt.getDataSource(). GetConnection()) при использовании шаблона Spring-Jdbc? Или они будут закрыты Template mechanizm?Spring-Jdbc Template and Prepared statement
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