Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I get auto-generated key by DB2

 
Suresh Yadla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am inserting a row into a table in DB2 and DB2 provides an auto-generated key into the primary key column.

After the insert I am retreiving that value by "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1", but the problem is how do I know that this is the ID that DB2 has generated for the above insert.. How do I ensure that no one else has done an insert and if someone else has done an insert then the IDENTITY_VAL_LOCAL() returns the ID of the second insert...

I am using JDBC 2.0 so I know that I cannot use, RETURN_GENERATED_KEYS in the preparedStatement. Is there any possible way that I can ensure that no one does a second insert until the IDENTITY_VAL_LOCAL() returns a value ?

Please help me out if you know, I would really appreciate your help.

Thanks,
Suresh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic