0

I created a sequence for id and I need max id from the table. So, I am using autoGeneratedKeys(), but it's not working.

public int createDataDAOImplentation(UserData c){
    int i=0; String sql="";
    try
    {
        ds.setPs("insert into contact(id,firstName,lastName,email,dob,gender)values(contact_seq.nextval,?,?,?,?,?)");
        ds.getPs().setString(1, c.getFirstname());
        ds.getPs().setString(2, c.getLastName());
        ds.getPs().setString(3, c.getEmail());
        ds.getPs().setint(4, c.getDob());
        ds.getPs().setLong(5, c.getGender());
        ds.getPs().executeQuery();
        ResultSet rs = ds.getPs().getGeneratedKeys();
        System.out.println("iam");
        if(rs.next()){
            i = rs.getInt(1);
            System.out.println("in"0);
        }
        ds.getCon().commit();
        ds.getCon().close();
    }
    catch(SQLException ex)
}

enter image description here

koPytok
  • 3,453
  • 1
  • 14
  • 29
shark
  • 15
  • 5

0 Answers0