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 > Informix > Obtaining the identity value...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-05, 10:44
pitris pitris is offline
Registered User
 
Join Date: Nov 2005
Posts: 5
Obtaining the identity value...

Hi

My java app makes an insertion in an Informix DB. One of the columns in the database is an autogenerated integer value, which is the primary key to the table. After the insert, I need to obtain that value so I can update another table. How can I do it?

In java, the PreparedStatement class can be set with the RETURN_GENERATED_KEYS parameter, allowing getGeneratedKeys() to be called for this purpose. However the Informix version that I'm using (9.2 or 9.3) doesn't support this method. Is there another way to do this?

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 12-13-05, 13:22
June C. Hunt June C. Hunt is offline
Registered User
 
Join Date: Feb 2005
Posts: 43
I'm not familiar with Java, but there is a built-in function within Informix that will get the last serial value inserted into the table. I'd think you should be able to use this. Take a look at the DBINFO function. Basically, you'd call the function as follows:

SELECT DBINFO('sqlca.sqlerrd1') FROM systables
WHERE tabname = <tablename>

Make sure to call this function immediately following a singleton INSERT into the table. DBINFO is documented in the IBM Informix Guide to SQL: Syntax manual.
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