i need last id that insert into persons for some manipulation in java. I have two insert then if I use getGeneratedKeys I get “operation not allowed” error. I use a select query to retrieve current value of sequence but it cause “an into clause is expected” error. How could I manage to access to last person id. The query:
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;
the java code:
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);