how to find the last insert id in java+mysql?
January 23rd, 2009One Comment
JDBC 3.0 (MySQL has a JDBC 3 compliant driver) method as such:
Statement stat = dbConn.createStatement();
Stat.executeUpdate("Some insert statement here");
Stat.executeUpdate("Some insert statement here");
ResultSet rs = stat.getGeneratedKeys();
Int insertedKeyValue = rs.getInt(1);
Rs.close();
Stat.close();


Friday, January 23rd, 2009 at 1:32 pm
if this doesn’t work, try putting a “rs.next()” before the getInt() statement, that should do the trick.