Java JDBC Get Last Inserted ID
Posted by tech on
June 10, 2008
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.
ResultSet rskey = ps.getGeneratedKeys(); if (rskey != null && rskey.next()) { int lastInsertedId = rskey.getInt(1); }








