Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verifying success for spring JDBC batch update

I am using Spring JDBCTemplate batchUpdate to insert data in a batch. I want to verify if the data is successfully inserted. JDBCTemplate batchUpdate returns an int[][], so which is the right way to verify that the data is inserted?

This link says "All batch update methods return an int array containing the number of affected rows for each batch entry. This count is reported by the JDBC driver and it's not always available in which case the JDBC driver simply returns a -2 value". I am unable to understand the significance of returning -2 value here. Does it means the insert was unsuccessful?

like image 829
Ayushi Avatar asked Oct 07 '13 13:10

Ayushi


1 Answers

-2 does not necessarily mean error, it might be as mentioned, the case of count of affected rows is not available.

EDIT

-2 is the value of Statement.SUCCESS_NO_INFO (while EXECUTE_FAILED is -3). So unless the driver does not comply with the JDBC specification, -2 unequivocally means success

END OF EDIT

The errors are reported via BatchUpdateException

Normally, if you run N queries in your batch script you will get the count of updates per query i in the result:

int result[] = jdbcTemplate.batchUpdate(sql);

so:

result[0]

will hold the update count for the first query,

result[1]

will hold the update count for the second query etc.

like image 78
aviad Avatar answered Nov 10 '22 13:11

aviad