Return value of the getUpdateCounts() of theh mssql-jdbc driver which comes with com.microsoft.sqlserver

25 Views Asked by At

Currently I'm processing a batch of data which saves into MSSQL database. And I'm using this jtds driver to get establish the database transactions.

   <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.2.8</version>
    </dependency>

While processing the batch I'm expecting there can be some rows which fail while inserting. I want to get to know exactly what are the failed rows for my requirement.

I used this getUpdateCounts() method to find the status of the processed records in the batch.

https://docs.oracle.com/javase/7/docs/api/java/sql/BatchUpdateException.html

But I'm not getting the expected result from this method. Assume the first record success and the second one failed. then the out put is something like this.

[-2, -3, -3, -3, -3, -3, -3, -3, -3, -3]

And if the first one fails and others success, still it's resulting like this way.

[-3, -3, -3, -3, -3, -3, -3, -3, -3, -3]

Then I thought of using the mssql-jdbc driver instead of the jtds driver.

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>12.4.1.jre8</version>
</dependency>

For run the project with this driver change, I have to do several changes in the project.

So I'm expecting valuable thoughts regarding this scenario.

0

There are 0 best solutions below