Primary key from inserted row jdbc?

后端 未结 7 1258
野趣味
野趣味 2020-12-05 06:23

Is there a cross database platform way to get the primary key of the record you have just inserted?

I noted that this answer says that you can get it by Calling

7条回答
  •  萌比男神i
    2020-12-05 07:12

    Just declare id column as id integer not NULL primary key auto_increment

    after this execute this code

    ResultSet ds=st.executeQuery("select * from user");
                    while(ds.next())
                    {
    
                     ds.last();
                    System.out.println("please note down your registration id  which is "+ds.getInt("id"));
                    }
                    ds.close();
    

    the above code will show you the current row's id

    if you remove ds.last() than it will show all values of id column

提交回复
热议问题