ORACLE JDBC Batch execution does not return the actual number of rows affected

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(); // I'm getting this connection properly
preparedStatement = connection.prepareStatement(sql);

for (String id : idList) { // idList is a List of String being passed to my method
    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.

, - ?

+4
3

- . PreparedStatement.

Javadoc Oracle , , , PreparedStatement. , Statement, .

:

Oracle , update counts array, executeBatch call . Oracle , :

, . , -2. JDBC 2.0, -2 , , .

, . Oracle .

1 , , .

+4

-2 - SUCCESS_NO_INFO, , . 11.2.0.3, JDBC . . PreparedStatement.

+1

, , ojdbc6.jar vs ojdbc5.jar, vs vs .

, :

ojdbc5.jar, java 5

ojdbc6.jar, java 6

/ orai18n.jar

, java , , -verbose java.

0

Source: https://habr.com/ru/post/1621763/


All Articles