简体   繁体   中英

I cannot extend the class in java

This is may one class. Now i want to create a new class registrationvalidator extending LoginValidator . i tried by

public class registrationvalidator extends LoginValidator {

}

But its show error in netbeans...What is the soluation?

public LoginValidator() throws SQLException{

    try {
        connect = new Dbconnect();
        st = connect.Statement();
    } catch (SQLException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public int validator(String mobileNo,String pass){
    int ret = 0;
    try{

        String query="select * from login where mobileNo='"+mobileNo+"'";
        res= st.executeQuery(query);
        while(res.next()){
            String dbMobileNo=res.getString("mobileNo");
            String dbPass=res.getString("password");

            if(mobileNo.equals(dbMobileNo) && pass.equals(dbPass)){
                ret=1;
            }
            else if(mobileNo.equals(dbMobileNo)){
                ret=2;
            }
        }


    }catch(SQLException ex){
        System.out.println("Sql Execption: "+ex);
        System.out.println("3"); 
    }

    return ret;
}
}

A few things here.

  1. You can only define one public class per java file. So your RegistrationValidator class should be in its own java file, separate from the LoginValidator class.
  2. Since you are catching the SQLException and logging some info, you don't need the "throws SQLException" for the constructor signature LoginValidator()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM