Menu

RETURN_GENERATED_KEYS doesn't work

Help
2008-07-10
2013-04-30
  • Edwin Clubb

    Edwin Clubb - 2008-07-10

    Hi.  I have been trying to retrieve the value of an auto-generated key.  Below is a snippet of code that, according to the JDBC documentation, should work:

    ----
    String sqlCmd2 = "INSERT INTO GLAD (ACN, TYPE, DESC1) VALUES (GLAD.NEXTVAL, 'A', 'New General Ledger Account')";
    out.println(sqlCmd2);
    stmt = con.createStatement();
    OK = stmt.executeUpdate(sqlCmd2, Statement.RETURN_GENERATED_KEYS);
    results = stmt.getGeneratedKeys();
    long newAcn;
    if (results.next()) {
        newAcn = results.getLong(1);
        out.println("<br />values returned = " + String.valueOf(newAcn));
    }
    out.println("Update result = " + OK);               
    results.close();
    stmt.close();
    con.close();
    ----

    Here is the resulting output.  The insertion of the record did succeed and the correct next key value was generated:

    ----
    INSERT INTO GLAD (ACN, TYPE, DESC1) VALUES (GLAD.NEXTVAL, 'A', 'New General Ledger Account')
    values returned = 0 Update result = 1
    ----

    This a feature I really need.  Any ideas about why this isn't working?

    Ed

     
    • Edwin Clubb

      Edwin Clubb - 2008-08-28

      Is anyone looking at this problem?

      Ed

       
    • Manoj Thoniyil

      Manoj Thoniyil - 2008-08-28

      I'm looking into this problem. I'll let you know as soon as I solve this.

      Thanks
      Manoj

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.