java - Delete from JDBC Derby Database using the auto-generated key (INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)) -


just wondering doing wrong here , how work around it. i've got simple table created so:

string createtablesql = (         "create table item_object_table ("         + "id integer not null generated identity (start 1, increment 1),"         + "item_object blob)");          preparedstatement ps = connection.preparestatement(createtablesql);          ps.execute(); 

the table stores blob of "item" object

anyway. delete method so:

public void deleteitem(int i) {     debug.write("attempting delete item id: "+i);     try       {         preparedstatement deletestatement = databaseconnector.preparestatement("delete item_object_table id=?");         deletestatement.setint(1, i);         deletestatement.execute();       } catch (sqlexception ex)       {         logger.getlogger(databasecontrol.class.getname()).log(level.severe, null, ex);       }  } 

this delete item not update integer id not null generated etc.

for example if database looked this:

 id 1 | blob data id 2 | blob data 

and called deleteitem(int id) method , parsed in int 1 (i.e. delete id 1) database this:

 id 2 | blob data 

the question is, how 'update' keys?

i'm little confused want here.

are saying when delete 1, expect id 2 updated use id 1 since id 1 gone?

if so, that's not how works, , fantastically inefficient , complex. have 200 tables referring id = 2 need cascading updates rename 1, , confusing db consumers well.

you may able control whether or not lowest available id reused instead of continuing highest id up, that's db specific question.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -