Getting auto-generated key from row insertion in spring 3 / PostgreSQL 8.4.9

后端 未结 9 1266
北荒
北荒 2020-12-04 17:40

I would like to retrieve the auto-generated id from a row insertion, but I get a NullPointerException

Here is the code :

long result = 0         


        
9条回答
  •  北海茫月
    2020-12-04 18:31

    Take a look at this post, especially the accepted answer of using the INSERT...RETURNING syntax:

    How to get a value from the last inserted row?

    This the best way to get this value in PostgreSQL as you only make one network round trip and it's done as a single atomic operation on the server.

提交回复
热议问题