禁用按钮没有正确调用java方法?

时间:2018-04-19 15:21:38

标签: java sql jsf stored-procedures facescontext

我在调用java方法时遇到了一些麻烦。所以,我在jsf的前端有按钮。在哪里,我调用我的java方法禁用2因素,我也有sql程序。如果一切顺利,任何人都可以检查我的java方法和我的sql语句。谢谢

这是我的代码: (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语句

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

1 个答案:

答案 0 :(得分:0)

我认为在您的java代码中,您希望通过procedure

更新数据库记录

所以将ps.executeQuery()更改为ps.executeUpdate()

因为ps.executeQuery()仅用于查询!