ID of last insert from DB2 table

Discussion in 'Java' started by mark.dundon, Jan 20, 2005.

  1. mark.dundon

    mark.dundon Guest

    I may have to migrate the database a Java application uses from MySQL
    to DB2. I am currently assessing the impact. One item I'm currently
    looking at is that of obtaining the ID of an insert immediately after
    the operation.

    For example with the MySQL database I would perform the following
    command:

    long lastInsertedID =
    ((com.mysql.jdbc.Statement)statement).getLastInsertID();

    The statement variable is of type java.sql.Statement.

    If I port over to DB2 I am concerned I cannot replace this
    functionality. A method such as .getLastInsertID() is not available
    from java.sql.Statement.

    Is there a solution if I port to DB2?
     
    mark.dundon, Jan 20, 2005
    #1
    1. Advertisements

  2. mark.dundon

    Dundonald Guest

    Apologies. I originally posted this to .programmer when I should have
    posted to .databases.

    Any ideas anyone please?
     
    Dundonald, Jan 20, 2005
    #2
    1. Advertisements

  3. mark.dundon

    Paul Guest

    IDENTITY_VAL_LOCAL() I suppose.
    http://publib.boulder.ibm.com/infoc...topic=/com.ibm.db2.udb.doc/admin/r0004231.htm

    Paul
     
    Paul, Jan 20, 2005
    #3
  4. mark.dundon

    Dundonald Guest

    Dundonald, Jan 20, 2005
    #4
  5. mark.dundon

    Chris Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Hi,

    How about the standard method java.sql.Statement.getGeneratedKeys()? I
    know it works with MySQL, but I'm not sure about DB2 (never used it).
    It's all dependent on whether the driver implements the method or
    not.

    Chrs
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.6 (GNU/Linux)

    iD8DBQFCBmU/gxSrXuMbw1YRAlyFAKCkN9Jzq2nNzBauwfRynNrKynRDzQCdHOZO
    nkKxoVdVhDYZ8dnwTqLG3Bc=
    =Pg17
    -----END PGP SIGNATURE-----
     
    Chris, Feb 6, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.