If you don't mind a few roundtrips to the database, then you could use the batchUpdate feature.
Here is an example where we pass in a JdbcTemplate and a List of Customer objects that should be deleted.
Code:
private void deleteBatch(JdbcTemplate jt, final List customers) {
int[] actualRowsAffected = jt.batchUpdate(
"delete from customer where id = ?",
new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setInt(1, ((Customer)customers.get(i)).getId());
}
public int getBatchSize() {
return customers.size();
}
});
}
You need to implement the BatchPrepareStatementSetter with two methods setValues and getBatchSize. The setValues methods gets a PreparedStatment and the index indicating the position in the batch. In our case this corresponds to the position in the List of Customer objects.