aspose file tools*
The moose likes JDBC and the fly likes How do I get auto-generated key by DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How do I get auto-generated key by DB2" Watch "How do I get auto-generated key by DB2" New topic
Author

How do I get auto-generated key by DB2

Suresh Yadla
Greenhorn

Joined: Mar 26, 2005
Posts: 12
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


Suresh Yadla<br />SCJP, SCWCD, SCBCD<br /> <br />----------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I get auto-generated key by DB2
 
Similar Threads
Question about sequences and entity ejbs 3.0
Insert Query with auto-incrementing key
Inserting table Record using iBator generated code , sqlerror code -440
DAO class design
After insert statement, how do I get column value populated by DB trigger