0

Hello folks I don't know where is the issue in the code can you help me please. ERROR 1: UsersDao is not abstract and does not override abstract method delete in DaoList. Error 2: Method does not override or implement a method from a supertype @Override

UsersDao.java :

public class Users extends db implements DaoList<Users>{
private static UsersDao userDao;
private UsersDao(){
}
public static UsersDao getInstance(){
    if(userDao == null){
        userDao = new UsersDao();
    }
    return userDao;
}
@Override
public List<UsersVo> loadAll(Users u) throws Exception {
    throw new UnsupportedOperationException("Not supported yet."); 
}
@Override
public int insert(Users u) throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    int count = 0;
    try{
    con = getConnection();
    String sql = "INSERT INTO USERS(USERNAME,PASSWORD,EMAIL) VALUES(?,?,?)";
    ps = con.prepareStatement(sql);
    ps.setString(1, u.getUserName());
    ps.setString(2, u.getPassWord());
    ps.setString(3, u.getEmail());
    count = ps.executeUpdate();
    }catch(Exception ex){
         
    }finally{
            ps.close();
            closeConnection(con);
    }
    return count;

}

@Override
public int update(Users u) throws Exception {
    throw new UnsupportedOperationException("Not supported yet."); 
}


@Override
public int delete(Users u) throws Exception {
    throw new UnsupportedOperationException("Not supported yet."); 
}

@Override
public PatientsVo getData(Users u) throws Exception {
    throw new UnsupportedOperationException("Not supported yet.");  
} } 
2
  • 1
    Two issues: 1. The insert method in your UsersDao class has a different signature to that of the ListDao interface (i.e. the UserVo parameter) hence the error for the @Override annotation. 2. The implementation must implement all the methods in the interface. Commented Jan 5, 2021 at 13:43
  • Hi @ stridecolossus I typed (pv.) by mistake it's edited, all method are implemented, I just didn't add them in the code to make it short
    – user14841908
    Commented Jan 5, 2021 at 14:08

1 Answer 1

2

The error is telling you the exact problem - your code is attempting to @Override a method that does not exist in its super-class or implemented interfaces.

The UsersDao implementation class has:

@Override
public int insert(UsersVo uv) throws Exception {
}

whereas the DaoList interface you are implementing has:

public int insert() throws Exception;

The method signatures are different (namely the UserVo parameter), the interface should be:

public int insert(UsersVo uv) throws Exception;

(Ditto for the other methods)

3
  • I dont see any anomaly in my code I update it please take a look in the code on the top if you can find something wrong thank you for your answer
    – user14841908
    Commented Jan 5, 2021 at 16:10
  • @Anass I've modified the answer to make it slightly more explicit but I'm not sure how to explain it any plainer - to repeat: the insert method in UsersDao is NOT the same as the corresponding method signature in the DaoList interface. It has to have the same signature. Commented Jan 5, 2021 at 16:35
  • its solved thank you @ stridecolossus I'm sorry I'm newbine in java programming and this code is from another developer on youtube the question how he did to insert the data even the abstract method insert in DaoList has not the same signature such as in the UsersDao class I mean the abstarct method insert(is empty) has no parameters in DaoList interface like I posted in the top
    – user14841908
    Commented Jan 5, 2021 at 17:40