0

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.

sohel khalifa
  • 5,602
  • 3
  • 34
  • 46

1 Answers1

1

It has been a while, but I think you can make another call to MySQL and get the ID. SELECT LAST_INSERT_ID(); perhaps?

Hope that helps!

Brandon

bcarlso
  • 2,345
  • 12
  • 12