2015-10-22 41 views
0

1.9.0我該怎麼做這個鍵下一個觸發驗證在java中驗證在Oracle的Java ADF

我什麼這樣的事情,但在Java ADF

protected PreparedStatement createStatementADF(String query) 
{ 
    PreparedStatement statement=null; 
    try { 

       /*create transaction for current statemtnt*/ 
       DBTransaction dbTransaction = (DBTransaction) this.getTransaction(); 
       statement= dbTransaction.createPreparedStatement(query, 0); 
    } catch (SQLException e) 
    { 
       throw new JboException(e); 
    } 
    return statement; 

} 
/*Executes single query*/ 
protected ResultSet executeQueryADF (String query, Object[] bindVars) 
{ 
      PreparedStatement statement=null; 
      ResultSet ret=null; 
      try { 

       /*create transaction for current statemtnt and resuse it*/ 
       statement=createStatementADF(query); 

       if ((bindVars != null)&&(statement!=null)) { 
        // 2. Loop over values for the bind variables passed in, if any 
        for (int z = 0; z < bindVars.length; z++) { 
         // 3. Set the value of each bind variable in the statement 
         statement.setObject(z + 1, bindVars[z]); 
        } 
       } 
       // 4. Execute the statement 
       ret=statement.executeQuery(); 
      } catch (SQLException e) { 
       throw new JboException(e); 
      } finally { 
       if (statement != null) { 
        try { 
         // 5. Close the statement 
         statement.close(); 
        } catch (SQLException e) { 
        } 
       } 
      } 
      return ret; 
} 
public void getUsrStatus() 
{ 
     ResultSet rs = null; 
     Object[] bindVars = new Object[]{"TestUser"}; 

     try { 
      rs = executeQueryADF("SELECT account_status FROM dba_users WHERE username = ?", bindVars); 
      while(rs.next()) 
      { 
       //..... process data 
      } 
     } catch (Exception e) 
     { 
     } 

    } 

在那裏我可以使用valueChangeListener,我如何驗證密碼,並調用過程驗證密碼,我已經基礎上,照耀處來驗證USEID

public void labelListener(ValueChangeEvent valueChangeEvent) 
    { UIComponent c = valueChangeEvent.getComponent(); 

    //This step actually invokes Update Model phase for this 
    //component 
    c.processUpdates(FacesContext.getCurrentInstance()); 

    //Jump to the Render Response phase in order to avoid 
    //the validation 
    FacesContext.getCurrentInstance().renderResponse(); 
    } 
+0

有問題嗎? – User404

+0

是的我該如何在adf中做這個驗證? – user3387275

+0

你想執行PL/SQL還是要將PL/SQL轉換爲Java? – User404

回答

0
  1. 創建視圖對象(VO),使用下面的查詢:

    SELECT account_status 
         FROM dba_users 
         WHERE username = :p_username 
    

    凡p_username是綁定變量,並添加VO到你的應用模塊(AM)

  2. 在你的就是你需要創建一個獲取VO的新方法, 設置綁定變量並執行VO。在這裏你通過檢查行數來檢查驗證,看看狀態是否正確。

根據您的使用情況,您應該在AM中顯示該方法(可能返回布爾值或字符串)。將該方法添加到綁定中,並在用戶執行某些操作(單擊按鈕)時執行該方法。隨着你的方法的結果,你可以做一些導航或顯示錯誤。 (拋出異常也可以作爲選項)。

編輯: 您可以將您的PL/SQL到一個函數/過程,並從AM執行。非常好的前:http://www.baigzeeshan.com/2010/05/calling-plsql-procedure-and-function-in.html

+0

我何時會調用過程併爲此 – user3387275

+0

IF轉換:work.accnt_stat = 'OPEN' 然後 validate_pswd( 'T', '數據庫用戶名', 空, null, passwd, wrk_err_ind, wrk_err_msg); IF nvl(wrk_err _,'N')='Y'THEN message(wrk_msg); raise form_trigger_failure; END IF; – user3387275

+0

@ user3387275我編輯了我的答案 – User404