Possible Duplicate:
PLSQL JDBC: How to get last row ID?
I have implemented a trigger and a sequence for auto incrementing PK, I'm using Oracle 10g as database. Now I want to INSERT something using JAVA, but I need to save the incremented PK in a variable right after the INSERT. I tried this:
PreparedStatement pstmt = connection.prepareStatement("INSERT INTO sometable
VALUES(?, ?)",
Statement.RETURN_GENERATED_KEYS);
pstmt.setInt(1, 5);
pstmt.setString(2, "Username");
pstmt.executeUpdate();
ResultSet resultSet = pstmt.getGeneratedKeys();
But it doesn't work.