I want to retrieve the most recently updated value in the table using an insert query.
these are the datatypes in my sql table.
Datatype:
You need to call rs.next()
:
int autoIncKeyFromApi = -1;
rs = stmt.getGeneratedKeys();
if (rs.next()) {
autoIncKeyFromApi = rs.getInt(1);
} else {
// do what you have to do
}
System.out.println(autoIncKeyFromApi);
Maybe it's because that the sqlQuery doesn't create any new record! In this case, it will return an empty ResultSet Look at the specification of getGeneratedKeys()