2010-12-01 13 views

Répondre

7

Il est utilisé pour l'insertion en vrac de plusieurs lignes à la fois.

This code illustre comment il est utilisé. Jetez un coup d'oeil à la méthode importEmployees, et tout deviendra clair.

+0

Merci vous tellement mec :) Maintenant clair :) –

0

batchUpdate peut être fait en utilisant la méthode JdbcTemplate batchUpdate comme suit ..

public int[] batchUpdate(final List<Actor> actors) { 
int[] updateCounts = jdbcTemplate.batchUpdate("update t_actor set first_name = ?, " + 
"last_name = ? where id = ?", 
new BatchPreparedStatementSetter() { 
public void setValues(PreparedStatement ps, int i) throws SQLException { 
ps.setString(1, actors.get(i).getFirstName()); 
ps.setString(2, actors.get(i).getLastName()); 
ps.setLong(3, actors.get(i).getId().longValue()); 
} 
public int getBatchSize() { 
return actors.size(); 
} 
}); 
return updateCounts; 
}