简体   繁体   English

禁用按钮未正确调用Java方法?

[英]Disable button not calling java method correctly?

I am having some trouble calling my java method. 我在调用我的java方法时遇到了一些麻烦。 So, I have button in my front end in jsf. 所以,我在jsf的前端有按钮。 Where, I am calling my java method to disable 2 factor, I have sql procedure as well. 在哪里,我叫我的java方法禁用2因素,我也有sql过程。 Can any one check my java method and my sql statement, if all is well. 如果一切正常,任何人都可以检查我的java方法和sql语句。 Thanks 谢谢

Here is my code: (java method) 这是我的代码:(java方法)

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 SQL语句

private static final String strDisableTwoFactor = "{call BEAN.DD_DISABLE_TWO_FACTOR(?,?,?,?,?,?)}";

I think in your java code you want to update the database record via procedure 我认为在您的Java代码中,您想通过procedure更新数据库记录

So change ps.executeQuery() to ps.executeUpdate() 因此将ps.executeQuery()更改为ps.executeUpdate()

Because ps.executeQuery() is just used for query! 因为ps.executeQuery()仅用于查询!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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