Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    9

    Unanswered: Managing identity column in java

    How can I retrieve the identity column value generated by DB2 when I make an INSERT using JDBC?
    I see IBM doc talking about VALUES IDENTITY_VALUE_LOCAL INTO :host-variable, but... I don't see how to translate the concept of 'host-variable' in java

    Thanks

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Quote Originally Posted by luca200
    How can I retrieve the identity column value generated by DB2 when I make an INSERT using JDBC?
    I see IBM doc talking about VALUES IDENTITY_VALUE_LOCAL INTO :host-variable, but... I don't see how to translate the concept of 'host-variable' in java

    Thanks
    You can use that in java, just take off the "INTO :hostvariable", issue it as a regular Statement and it will be returned in the ResultSet.

    There's also a new method getGeneratedKeys() that was introduced in JDBC, for use with Statement or PreparedStatement objects. I'm not sure if DB2 conforms to it yet, though, might want to give it a try. It returns a ResultSet.
    --
    Jonathan Petruk
    DB2 Database Consultant

  3. #3
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    9
    Quote Originally Posted by J Petruk
    You can use that in java, just take off the "INTO :hostvariable", issue it as a regular Statement and it will be returned in the ResultSet.
    Thank you, I'll try
    Quote Originally Posted by J Petruk
    There's also a new method getGeneratedKeys() that was introduced in JDBC, for use with Statement or PreparedStatement objects. I'm not sure if DB2 conforms to it yet, though, might want to give it a try. It returns a ResultSet.
    I found it in docs, but I can't use it because I have Java 1.3.1....

    thanks anyway :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •