我需要最後一個id,插入到人員中以便在java中執行一些操作。 我有兩個插入,然後如果我使用getGeneratedKeys我得到「操作不允許」的錯誤。我使用select查詢來檢索當前的序列值,但它會導致「預期的進入子句」錯誤。我怎麼能設法訪問最後一個人的ID。 查詢:如何在不使用seq.currval的情況下檢索序列的當前標識
begin
insert into Persons
(Id,First_Name,Last_Name)
values (person_seq.nextval ,? ,? );
insert into Relations (relation_id, person_id)
values (relation_seq.nextval,person_seq.currval);
SELECT person_seq.currval FROM DUAL;
end;
java代碼:
stmt = connectionManager.getConnection().prepareStatement(query);//,new String[] {"ID"});
stmt.setString(1, family.getFName());
stmt.setString(2, family.getLName());
ResultSet resultSet = stmt.executeQuery();
ret = resultSet.getLong(1);
可能重複[如何獲得來自最後插入的行的值?](http://stackoverflow.com/questions/241003/how-to-get-a-value-from-the-last-inserted-row) – user1717259 2015-02-10 16:30:46
我在此查詢中有2個插入。那麼我不能使用生成的密鑰,當我使用返回我有錯誤,我不能獲取它返回。 – user4002899 2015-02-10 17:20:22