2013-11-28 73 views
0

我想把其他或切換語句,這是更適合檢查之前提交的僱員數。如果我把我的if else或切換代碼。如果count爲5,那麼我想限制員工,然後顯示消息「達到最大員工限制」,否則允許提交。 我在java的PLZ一個新幫我解決這個java檢查條件後提交之前點擊保存按鈕

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; 
}} 

我的錯誤日誌

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 
+2

-1對於錯誤的代碼格式。 –

+0

除非先決條件已經滿足,否則禁用該按鈕將更重要。 – EJP

回答

0

請關閉您的try catch塊正確

try{ 

}catch(Exception e){ 

}finally{ 

} 

和閱讀this

+0

感謝親愛的回覆。你能編輯這段代碼嗎 – user3024346

0

catchfinally是內嘗試block

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

謝謝vinayat的幫助,你可以幫我解決哪些條件更適合多種條件if else或switch – user3024346

+0

@ user3024346 switch語句比if-else-if梯子執行的更快。這是由於編譯器能夠優化switch語句。對於if-else-if梯形圖,代碼必須按照程序員確定的順序處理每個if語句。但是,由於switch語句中的每個case不依賴於以前的情況,因此編譯器能夠以提供最快執行的方式使用分支表 –

+0

感謝親愛的幫助 – user3024346

0

使用IDE會幫助您縮進和正確的格式,同時編寫代碼。例如Eclipse

對於第一個錯誤關閉的try-catch塊正常
而對於第二個錯誤:由於您的方法聲明爲public String cmdSave_action(),你應該在方法的最後返回一個String值。您的代碼中缺少return聲明。