Skip to content
Advertisement

executeUpdate() returns always 1 with MERGE statement

ExecuteUpdate() is always returning 1. Pls suggest and appreciate any input.

Procedure:

JavaScript

Java code:

JavaScript

stmt.executeUpdate() – always returns 1, even though insertion happens only once. Appreciate any inputs on this. Ideally, if there are no insertions or errors, it should return 0 or any exception trace. Pls, suggest.**

Advertisement

Answer

We can make the column a primary key. Now when multiple VM’s tries to execute, the other one will throw a Unique Integrity exception and in the catch block, we can read the SQLException. Once we read the SQLException, we can also read the sqlstate and we can perform the needed operations based on the sqlstate.

Sample code below

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement