Is there a way to check if expected update query rows are equal to the actual ones?

Viewed 30

In my automation testing infrastructure, we have a test that gets query and expected result and runs it and checks that the value is correct. However, sometimes the query is update\insert, and we fail the test only if the number of rows affected is zero. What I want to do is to fail the test if only 1 row was affected instead of 4 expected. The database has found only 1 row that can be updated, but the rest of the 3 not. What can I do to achieve it?

Here is a snippet of the code:

//conn and query already defined and given
Statement stmt = conn.createStatement()
if (!stmt.execute(query)) {
            int updatedRows = stmt.getUpdateCount();
            if(updatedRows == 0) {
                System.out.println("Update or insert query didn't affect any rows!");
            }
0 Answers
Related