Results 1 to 3 of 3

Thread: [RESOLVED] Retrieving the autogenerated key while doing an INSERT?

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Resolved [RESOLVED] Retrieving the autogenerated key while doing an INSERT?

    Hey there. I've currently got this SQL statement:

    INSERT INTO Inlagg (rubrik, anvandare, inlaggText) VALUES ('" + rubrik +"', '" + anvandare.getAnvandarnamn() + "', '" + inlaggText + "')"

    I've set it up to autogenerate a key when a row is inserted into the table. My problem now is that I need to use this key immediately after inserting the row, is there any way to insert the row and retrieve the autogenerated key in one go?

    Im using Java (So I guess its ...JDBC?) and an Access 2002 database.

    Help would be much appreciated. Thanks.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Retrieving the autogenerated key while doing an INSERT?

    You can't get it in the same statement (unless JDBC offers that feature, but I doubt it), but can in a separate statement which is reliable, as shown in the FAQ How can I get the auto-generated AutoNumber/Identity value for the record just added?

  3. #3

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Retrieving the autogenerated key while doing an INSERT?

    Ah I see.
    Thanks si!
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

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



Click Here to Expand Forum to Full Width