How can I treat a sequence value like a generated key?

Posted by Jeff Knecht on Stack Overflow See other posts from Stack Overflow or by Jeff Knecht
Published on 2010-04-30T15:42:53Z Indexed on 2010/04/30 19:57 UTC
Read the original article Hit count: 154

Filed under:
|
|
|

Here is my situation and my constraints:

  1. I am using Java 5, JDBC, and DB2 9.5

  2. My database table contains a BIGINT value which represents the primary key. For various reasons that are too complicated to go into here, the way I insert records into the table is by executing an insert against a VIEW; an INSTEAD OF trigger retrieves the NEXT_VAL from a SEQUENCE and performs the INSERT into the target table.

  3. I can change the triggers, but I cannot change the underlying table or the general approach of inserting through the view.

  4. I want to retrieve the sequence value from JDBC as if it were a generated key.

Question: How can I get access to the value pulled from the SEQUENCE. Is there some message I can fire within DB2 to float this sequence value back to the JDBC driver?

© Stack Overflow or respective owner

Related posts about java

Related posts about db2