可能重複:
Retrieve id of record just inserted into a Java DB (Derby) database找我剛纔插在德比數據庫記錄的ID
我有一個Derby數據庫與列創建一個表:
id INTEGER GENERATED ALWAYS AS IDENTITY
如何獲取插入的最後一條記錄的ID? 我怎麼知道我剛剛插入的記錄的ID是什麼?
可能重複:
Retrieve id of record just inserted into a Java DB (Derby) database找我剛纔插在德比數據庫記錄的ID
我有一個Derby數據庫與列創建一個表:
id INTEGER GENERATED ALWAYS AS IDENTITY
如何獲取插入的最後一條記錄的ID? 我怎麼知道我剛剛插入的記錄的ID是什麼?
Java的聲明類具有的getGeneratedKeys(),其目的是提供一個信息:
http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGeneratedKeys()
的IDENTITY_VAL_LOCAL()函數應該是您的朋友:http://db.apache.org/derby/docs/10.2/ref/rrefidentityvallocal.html
...雖然這會將您綁定到Derby。 – 2011-04-26 11:12:33
這與java-ee無關。將標記更改爲'java' – 2011-04-26 11:07:54