If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Retrieving an auto-generated key from an insert with java

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-17-04, 13:41
sde sde is offline
Registered User
 
Join Date: Apr 2004
Location: us.ca
Posts: 9
Retrieving an auto-generated key from an insert with java

There is a table which increments the primary key field by 1 for each new entry.

Is there a way to retrieve the value of this key?

for example: AGENTID,AGENTNAME .. the agent id field increments.

my sql statement that i use with jdbc looks like this: INSERT INTO FILE (AGENTNAME) VALUES('ME')

and now i need the ID it generated. do i need to do another query?
Reply With Quote
  #2 (permalink)  
Old 06-17-04, 16:01
Isaac E Isaac E is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
retrieve an auto-generated ID

Try
SET :your-receiving-field = IDENTITY_VAL_LOCAL()
after insert
This function returns your last inserted id

By the way this is the COBOL format which may be different a little from Java

Isaac ElSerafi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On