Reputation: 5378
String[] sql={"insert into customer(name,age) values('v1',21)",
"insert into customer(name,age) values('v2',22)",
"insert into customer(name,age) values('v3',23)",
"insert into customer(name,age) values('v4',24)" };
jdbcTemplate.batchUpdate(sql);
How to know whether this batchupdate statement is executed successful.
Upvotes: 3
Views: 15605
Reputation: 12924
Batch update methods return an int array containing the number of affected rows for each statement. I.e in your case you can capture as below.
int result[] = jdbcTemplate.batchUpdate(sql);
So in your,
result[0]
you get the update count of insert into customer(name,age) values('v1',21)
query,
result[1]
you get the update count of insert into customer(name,age) values('v2',22)
query and so on.
If there any run time errors you will get BatchUpdateException.
Upvotes: 5