I am creating a simple application in JSP- JDBC for inserting and updating details of employees.
The database is in MySql.The primary key in master table is set to auto increment. Now when i'm inserting a new employee details, I want to show a newly generated Key in a textfield in JSP.
Is there a way for doing it.??
this is the method i've created in DAO class..
public int getMaxId()
{
int id=0;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select MAX(emp_id) from emp_details");
id = rs.getInt("emp_id");
}catch(Exception e)
{
e.printStackTrace();
}
return id;
}
But its shows java.sql.SQLException: Column 'emp_id' not found.