简体   繁体   中英

java check condition after clicking on save button before commit

i want to put if else or switch statement which is more suitable for checking employee count before commit.where i put my if else or switch code . i want restriction on employee if count is 5 then its show message "reached maximum employee limites" otherwise allow commit. i am new in java plz someone help me to solve this

    public String cmdSave_action()

{
    // my code before 

    {
    DeptSet result;
       try {
           dbo.connect();

           result = 
                   dbo.execSQL("select count(*) from empmasterinfo where mainid='ORGElement' and designationid='?') "
                               (inputText_ORGElement.getValue() != null ? 
             ""));

        result = dbo.execSQL(sSQL);

      catch (Exception e) {
    System.out.println(e.getMessage());
       finally 
       {
       dbo.close();                         
       }
       return null;
    }}}

    // my code above

  {  
    Global.PerformIteratorAction(this.bindings, "Commit");
    AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
    afContext.getProcessScope().put("EmployeeID", 
                                    Global.getCurrRowFieldValue("EmpmasterinfoViewIterator", 
                                                                "Employeeid"));
    if (afContext.getProcessScope().get("AddEdit").toString().equals("0"))

    {
        Global.PerformIteratorAction(this.bindings, 
                                     "EPR_TRANSFER_APPLICANT_INFO");
        Global.PerformIteratorAction(this.bindings, "eprGenerateApPlan");
    }
    return null;
}}

My Error Log

Error(149,12): 'try' without 'catch' or 'finally'
Error(154,36): , expected
Error(157,34): field SQL not found in class hcm.view.backing.empprofile.EmployeeMasterInfo_Add
Error(159,11): illegal start of expression
Error(159,11): ; expected

E:\HCM\ViewController\src\hcm\view\backing\empprofile\dbo.java
Error(13,16): method does not return a value

Please close Your try catch block properly

try{

}catch(Exception e){

}finally{

}

And Read this

catch and finally are within try block

try {
//code
}
catch(Exception e) {
System.out.println(e.getMessage());
}
finally {
dbo.close();
}

Using an IDE will help you with indentation and proper formatting while writing code. eg Eclipse .

For the first error close the try-catch blocks properly
And for the second error: Since your method is declared as public String cmdSave_action() , you should return a String value at the end of the method. The return statement is missing in your code.

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