INSERT, and get the auto-incremented value

后端 未结 3 1545
梦毁少年i
梦毁少年i 2021-01-20 15:22

Consider the following table:

create table language (
    id integer generated always as identity (START WITH 1, INCREMENT BY 1),
    name long varchar,
             


        
3条回答
  •  花落未央
    2021-01-20 16:07

    Through plain SQL:

     insert into language(name) values ('value');
     SELECT IDENTITY_VAL_LOCAL();
    

    See the manual for details: http://db.apache.org/derby/docs/10.7/ref/rrefidentityvallocal.html

    When doing this from a Java class (through JDBC) you can use getGeneratedKeys() after "requesting" them with the approriate executeUpdate() method.

提交回复
热议问题