1
votes

I have spent about 3 hours checking on the internet and I still can't find the answer to this question.

The java documentation and also this tutorial says:

Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing

So what it would mean is:

  • Insert 1 row without duplicates -> 1
  • Insert 3 rows without duplicates -> 3
  • Insert 3 rows with all duplicates and none updating a value -> 0
  • Insert 3 rows with 2 no-duplicates and 1 duplicate that updates a value -> 3
  • Insert 3 rows with 2 no-duplicates and 1 duplicate that doesn't update a value -> 2

Or at least this is what I understand from the documentation.

However, reading other questions here and here on StackOverflow got me confused again since it doesn't describe this behavior, instead it describes what the MySQL documentation says

With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values.

This would still make sense if the former behavior was exclusive to Java using the connector and the later through direct MySQL manipulation, but as I said before, I have found answers that say it uses either the first or the second contradicting each other.

This is important for me because on my code, I perform an insert with on update of many entries and check if it was performed successfully by comparing the return number, with my array to modify count.

1
Write the code to test this and you will get your answer.Luiggi Mendoza
The compensateOnDuplicateKeyUpdateCounts configuration property described here might also affect the results you are seeing.Gord Thompson

1 Answers

0
votes

The MySQL Reference Manual says:

With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, and 2 if an existing row is updated.