Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derby JavaDB Query ON DUPLICATE KEY UPDATE

I know that MySQL supports this query (ON DUPLICATE KEY UPDATE) for example:

INSERT INTO UserFailure (Realm, Username, DateOfFailure, CountOfFailure) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE CountOfFailure=?;

When I am running this on embedded Derby DB it gives me:

PreparedStatementCallback; bad SQL grammar [INSERT INTO UserFailure (Realm, Username, DateOfFailure, CountOfFailure) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE CountOfFailure=?;]; nested exception is java.sql.SQLSyntaxErrorException: Syntax error: Encountered "ON" at line 1, column 91.

I assume that Derby does not support this feature.

Is there a query I can use to update the database record on duplicate key from Derby and from MySQL?

like image 668
Paulius Matulionis Avatar asked Dec 18 '25 15:12

Paulius Matulionis


1 Answers

You can catch the duplicate key exception yourself, and issue the update.

like image 158
Bryan Pendleton Avatar answered Dec 21 '25 04:12

Bryan Pendleton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!