• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I get auto-generated key by DB2

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic