I am working on an application in which I use JDBC and Oracle11 .
I have hundreds of thousands of records in my table tbltestthat I update using JDBC batch execution . Therefore, we consider it as one id = one request.
My requirements: I want to keep track of which idwere successfully updated and which do not exist in db.
Below is my code:
String sql = "UPDATE TBLTEST SET STATUS = 'CANCEL' WHERE ID = ?";
PreparedStatement preparedStatement = null;
Connection connection = getConnection();
preparedStatement = connection.prepareStatement(sql);
for (String id : idList) {
preparedStatement.setString(1, id);
preparedStatement.addBatch();
}
int[] affectedRecords = preparedStatement.executeBatch();
System.out.println("Records affected:"+Arrays.toString(affectedRecords));
int success = preparedStatement.getUpdateCount();
System.out.println(success + " Total updated");
idList. this Javadoc, affectedRecords, . , , .
affectedRecords, -2. , idList 5 :
:
Records affected: [-2, -2, -2, -2, -2]
5 Total updated
:
Records affected: [1, 1, 1, 1, 1]
5 Total updated
, :
https://community.oracle.com/thread/3691652?start=0&tstart=0
https://community.oracle.com/thread/1046798?tstart=0
, , , ojdbc6.jar.
, - ?