Re: ID of last insert from DB2 table - JDBC JAVA

This is a discussion on Re: ID of last insert from DB2 table - JDBC JAVA ; mark.dun... wrote: > 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Re: ID of last insert from DB2 table

  1. Default Re: ID of last insert from DB2 table


    mark.dun... wrote:
    > 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?


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

    Any ideas anyone please?


  2. Default Re: ID of last insert from DB2 table

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

    Dundonald wrote:

    >
    > mark.dun... wrote:
    >> 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?


    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-----

+ Reply to Thread

Similar Threads

  1. INSERT INTO doesn't wait for table creation...
    By Application Development in forum Inetserver
    Replies: 3
    Last Post: 11-24-2007, 04:45 PM
  2. Insert records and then return ID to insert into sub table
    By Application Development in forum ADO DAO RDO RDS
    Replies: 1
    Last Post: 06-10-2007, 07:58 PM
  3. Ind CS2 : is it possible to insert a footnote in a table?
    By Application Development in forum Adobe Indesign
    Replies: 2
    Last Post: 12-15-2006, 02:35 AM
  4. Insert into child table fails
    By Application Development in forum basic.visual
    Replies: 1
    Last Post: 10-22-2005, 08:50 AM
  5. DAO and VBA to insert an OLE into a table
    By Application Development in forum ADO DAO RDO RDS
    Replies: 0
    Last Post: 02-06-2004, 01:51 PM