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");

ResultSet rs = stat.getGeneratedKeys();
Int insertedKeyValue = rs.getInt(1);

Rs.close();
Stat.close();

Related Posts:

Tagged : ,

One Responses

  1. if this doesn’t work, try putting a “rs.next()” before the getInt() statement, that should do the trick.

Leave a Reply