If you don’t like stored procedures wherein the value returned is the last inserted id, you can get it via JDBC code. Using either a Statement or PreparedStatement class, you retrieve the ResultSet using the getGeneratedKeys() method. Sample code below.
|
1 2 3 4 5 |
ResultSet rskey = ps.getGeneratedKeys(); if (rskey != null && rskey.next()) { int lastInsertedId = rskey.getInt(1); } |