0

I am having some trouble calling my java method. So, I have button in my front end in jsf. Where, I am calling my java method to disable 2 factor, I have sql procedure as well. Can any one check my java method and my sql statement, if all is well. Thanks

Here is my code: (java method)

public void disableTwoFactor() throws SQLException {
    CallableStatement ps = null;
    Connection conn = null;
    ResultSet result = null;
    getConfirmationCode();

    if (confirmationCodeFromUser.equals(Integer.toString(confirmationCodeFromServer))) {

        try {

            //get database connection
            conn = DataUtility.getDataSource().getConnection();

            ps = conn.prepareCall(strDisableTwoFactor);  

            ps.clearParameters();

            ps.setInt(1, this.id);
            ps.setString(2, this.number);
            ps.setString(3, this.passwordConfirmationStatus);
            ps.registerOutParameter(4, OracleTypes.CURSOR);
            ps.executeQuery();

            getPassStatus(conn);
            result = (ResultSet) ps.getObject(4);
            result.next();
            if (result.getString(1).equals("YES")) {
                if (displayPassSignupPage == true) {
                    FacesContext.getCurrentInstance().addMessage("codeVerify",
                            new FacesMessage("You  are now two-factor free"));
                } else {
                    FacesContext.getCurrentInstance().addMessage("codeVerify",
                            new FacesMessage("You  are now two-factor free"));
                }

            } 

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (ps != null) {
                ps.close();
            }
            if (conn != null) {
                conn.close();
            }
            ps = null;
            conn = null;
        }

    }  
} 

SQL Statement

private static final String strDisableTwoFactor = "{call BEAN.DD_DISABLE_TWO_FACTOR(?,?,?,?,?,?)}";
DAIRAV
  • 723
  • 1
  • 9
  • 31
  • Narrow down the problem. 99.999% of the JSF questions is NOT sql related (not evgen JPA). and 99.99999% of the SQL questions is not JSF related. If the method is not called it is not SQL related. Remove all that code from your Q and make it a [mcve]. And there is NOTHING JSF related in your question so it is effectively a rather bad investigated and formulated one. Oh and if it is a jsf related method, it is bad practice to have it throw an SQLEXception... Read https://stackoverflow.com/questions/30639785/jsf-controller-service-and-dao – Kukeltje Apr 19 '18 at 17:36
  • http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Apr 19 '18 at 17:46

1 Answers1

0

I think in your java code you want to update the database record via procedure

So change ps.executeQuery() to ps.executeUpdate()

Because ps.executeQuery() is just used for query!

flyingfox
  • 13,414
  • 3
  • 24
  • 39
  • that's good but my method is not firing still. Is everything seems fine? –  Apr 19 '18 at 15:34
  • you mean your method is not invoked?Then you need to debug your code to find why,especially `if (confirmationCodeFromUser.equals(Integer.toString(confirmationCodeFromServer)))` – flyingfox Apr 19 '18 at 15:37
  • Thanks for trying to help. And weird... Who upvoted this answer? – Kukeltje Apr 19 '18 at 17:37
  • @Kukeltje I do not know who upvote it,but why you down vote it? I have point out a bug for it,I think that's the reason why someone upvote it – flyingfox Apr 20 '18 at 01:36
  • Because your answer is not related to the question. The method is not even called so the cause is before all the sql stuff. OP tagged and formulated the question totally wrong. You might be right that it is wrong but that is more an additional comment than the reason for the actual problem – Kukeltje Apr 20 '18 at 06:43