java - JDBC generated key from insert on duplicate -


if have insert on duplicate key clause, , there duplicate key, there way primary key duplicated? or have own manual query? far can tell getgeneratedkeys() callablestatement class not return new insert wasn't done.

edit sorry if wasn't clear want primary key of record back.

so if have following table (excuse syntax, typing freehand):

create table some_table(   id int(11) unsigned not null auto_increment,   value varchar(500)not null,   count int(10) unsigned not null default '0',   primary key (id),   unique key (value) );  insert some_table(value) on duplicate key update count = count + 1; 

if add 'test' value, new record added , id returned getgeneratedkeys();

if attempt add 'test' again, key exists , therefore count updated. want primary key/id of row updated. have see no results getgeneratedkeys() - none generated - , select after fact?

on duplicate key update count = count + 1, id = last_insert_id(id) 

note: shouldn't necessary of mysql 5.5.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -