Forums Register Login

How do I get auto-generated key by DB2

+Pie Number of slices to send: Send
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
Men call me Jim. Women look past me to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2177 times.
Similar Threads
Question about sequences and entity ejbs 3.0
Inserting table Record using iBator generated code , sqlerror code -440
After insert statement, how do I get column value populated by DB trigger
DAO class design
Insert Query with auto-incrementing key
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:09:48.