Thanks. I found the solution as follows:
stmt.executeUpdate(insertSQL,Statement.RETURN_GENERATED_KEYS);
int autoIncKeyFromApi = -1;
rs = stmt.getGeneratedKeys();
if (rs.next()) {
autoIncKeyFromApi = rs.getInt(1);
} else {
// throw an exception from here
}
I am using mysql database.
In my jsp page, after inserting a record in the mysql table, I need to get back the new ID generated for the auto_increment primary key column. How do I get this value?
My servlet gets redirected properly to a jsp page(MyPage.jsp), but clicking the links on that jsp page fails.
Get the error:
The requested resource (/CC/servlet/Main.jsp) is not available.
In MyPage.jsp page, the link is defined as follows:
<a href="Main.jsp">Back to Main Page</a>
but after...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.