Java – find the content updated or inserted by MySQL query execution
•
Java
My inquiry is as follows
INSERT INTO MYTABLE (f1,f2,f3,f4) VALUES (1,2,3,4) ON DUPLICATE KEY UPDATE f4=5;
I've achieved it,
Create the connection, declare and execute the query as follows
statement.execute(query);
But now I need to find out whether the code executes insert or update?
Who can help me with this??
Thank you in advance
Solution
I don't know any specific built-in features or solutions
But in my case, I will make it possible in a simple way
select count(*) as oldcount from MYTABLE;
Execute your query at this level
INSERT INTO MYTABLE (f1,4) ON DUPLICATE KEY UPDATE f4=5; select count(*) as newCount from MYTABLE; retrive OLDCOUNT and NEW COUNT if(oldcount != new count) { //InsertPerformed } else { //updateperformed }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码