What’s the best way to get the last inserted id using sqlite from Java? Google is giving me different answers–some say select the last-insert-rowid; others say call statement.getGeneratedKeys(). What’s the best route to take? (I just want to return the id, not use it for other inserts or anything.)
Share
Use
getGeneratedKeys()if your JDBC driver supports it. You don’t want to muck around trying to get the key yourself after the insert. If your driver does not supportgetGeneratedKeys()then I would get the next value from the key before the insert.