Batch updating a array of actors
I have created the following method, to update an array of actors using a prepared statement. i could not make it work, i sort of know the problem but don't know how to fix it, any help.
Here is some of the code i have so far.
public void JdbcBatchUpdate(List<Actor> actors) {
String sql = "select * from Actor";
Connection conn = null;
try {
conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(sql);
ps.addBatch("update actor set first_name= ? where actor_id='?'");
//ps.setInt(1, actors.);
ps.executeBatch();
int[] updCnt = ps.executeBatch();
ps.close();
conn.rollback();
//conn.commit();
} catch (BatchUpdateException be) {
//handle batch update exception
int[] counts = be.getUpdateCounts();
for (int i = 0; i < counts.length; i++) {
System.out.println("Statement[" + i + "] :" + counts[i]);
}
} catch (SQLException e) {
}
}
Thank you