I've a query as follows...
INSERT INTO MYTABLE (f1,f2,f3,f4) VALUES (1,2,3,4) ON DUPLICATE KEY UPDATE f4=5;
That I've achieved through,
Creating a connection,statement & executing the query as follows
statement.execute(query);
But, now I need to find whether the code had performed an INSERT or UPDATE ?
Can anyone help me with this??
Thanks in advance...
You might use instead two statements: executeUpdate
returns the number of rows affected. If that number is 0, then you have to perform an insert.
I dont know any specific built in function or work around.
But in my case I would have made it possible like this in an easy way
select count(*) as oldcount from MYTABLE;
perform your Query at this level
INSERT INTO MYTABLE (f1,f2,f3,f4) VALUES (1,2,3,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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With