db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John English <john.fore...@gmail.com>
Subject Duplicate key feature request
Date Sat, 29 Nov 2014 12:25:14 GMT
Something that I find crops up quite often is code to deal with duplicate keys. 
I often want to insert into a table, or update if the key already exists. In 
MySQL I can just use INSERT ... ON DUPLICATE KEY UPDATE ... for this, but with 
Derby I end up with code that looks like this:

   try {
     //... insert new row
   catch (SQLException e) {
     if (e.getSQLState().equals(DUPLICATE_KEY)) {
       // ... update existing row
     else {
       throw e;

In the absence of something like INSERT ... ON DUPLICATE KEY UPDATE, would it 
not perhaps be a good idea for Derby to subclass SQLException so that it could 
throw a (say) SQLKeyExistsException to avoid ugly repetitive code like the 
above? Or is there already something that I've overlooked that addresses this 

John English

View raw message