Professional Web Applications Themes

retrieve generated ID - IBM DB2

Hi, I'm using a JDBC T4 driver to connect to a DB2 8.2 database. Is there an easy way to retrieve the value of a generated key, other than creating a SQL query to retrieve it?? create table TEST.ORDER ( ORDERID ID not null generated by default as identity, ORDERSTATUSID ID not null, SEMIPRODUCTID ID not null, .... ); int result = 0; String SQL ="insert into test.order (orderstatusID, semiProductID...) " + "values (cast (? as ID), cast (? as ID), ...)"; PreparedStatement stmt = connection.prepareStatement(SQL); stmt.setInt(1, orderStatusID); stmt.setInt(2, semiProductID); .... try { stmt.executeUpdate(); result = stmt.getUpdateCount(); // What is ...

  1. #1

    Default retrieve generated ID

    Hi,

    I'm using a JDBC T4 driver to connect to a DB2 8.2 database.
    Is there an easy way to retrieve the value of a generated key, other
    than creating a SQL query to retrieve it??

    create table TEST.ORDER
    (
    ORDERID ID not null generated by
    default as identity,
    ORDERSTATUSID ID not null,
    SEMIPRODUCTID ID not null,
    .... );



    int result = 0;
    String SQL ="insert into test.order (orderstatusID, semiProductID...) "
    + "values (cast (? as ID), cast (? as ID), ...)";

    PreparedStatement stmt = connection.prepareStatement(SQL);

    stmt.setInt(1, orderStatusID);
    stmt.setInt(2, semiProductID);
    ....

    try {
    stmt.executeUpdate();
    result = stmt.getUpdateCount();

    // What is the value of orderID????

    } catch (SQLException e) {
    ....
    }

    stmt.close();
    stmt = null;




    Thanx for any help,
    Marcel

    Marcel Guest

  2. #2

    Default Re: retrieve generated ID

    Marcel <mr_nospamvgelder.com> wrote:
    > Hi,
    >
    > I'm using a JDBC T4 driver to connect to a DB2 8.2 database.
    > Is there an easy way to retrieve the value of a generated key, other
    > than creating a SQL query to retrieve it??
    >
    > create table TEST.ORDER
    > (
    > ORDERID ID not null generated by
    > default as identity,
    > ORDERSTATUSID ID not null,
    > SEMIPRODUCTID ID not null,
    > .... );
    Have a look at the IDENTITY_VAL_LOCAL() function.

    --
    Knut Stolze
    Information Integration
    IBM Germany / University of Jena
    Knut Stolze Guest

Similar Threads

  1. Retrieve URL from DB
    By coryd218 in forum Coldfusion Database Access
    Replies: 2
    Last Post: May 6th, 02:38 PM
  2. Retrieve URL with dynamically generated # using WinHttp
    By thuratin@yahoo.com in forum ASP Components
    Replies: 0
    Last Post: March 19th, 11:30 PM
  3. Alter generated always to generated by default
    By Doug Schaible in forum IBM DB2
    Replies: 0
    Last Post: August 13th, 09:44 PM
  4. retrieve *.jpg
    By ma in forum Microsoft Access
    Replies: 0
    Last Post: August 4th, 04:45 PM
  5. Need to retrieve records
    By MLangner-MMTS in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 12th, 11:14 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139