Example usage for java.sql CallableStatement executeUpdate

List of usage examples for java.sql CallableStatement executeUpdate

Introduction

In this page you can find the example usage for java.sql CallableStatement executeUpdate.

Prototype

int executeUpdate() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Usage

From source file:org.wso2.ws.dataservice.DBUtils.java

private static OMElement getStoredProcedureResult(OMElement queryElement, HashMap inputValues, HashMap params,
        HashMap paramOrder, HashMap originalParamNames, HashMap paramType, AxisService axisService,
        int queryLevel) throws AxisFault {
    OMElement resultElement = null;/*w  ww .  j  av a  2 s. co m*/
    Connection conn = null;
    boolean noResultSet = false;
    String elementValue;
    boolean hasResponse = true;
    OMNamespace omNs = null;
    String sqlQuery = queryElement.getFirstChildWithName(new QName("sql")).getText();
    try {
        //Parameter dbConnectionParam = axisService.getParameter(DBConstants.DB_CONNECTION);  
        //if(dbConnectionParam == null){
        //   throw new AxisFault("Database connection not found in Axis Configuration");
        //}
        //conn = (Connection)dbConnectionParam.getValue();
        conn = checkDBConnectionStatus(axisService, conn);
        conn.setAutoCommit(false);
        CallableStatement cs = (CallableStatement) getProcessedPreparedStatement(inputValues, params,
                paramOrder, originalParamNames, paramType, conn, sqlQuery, "STORED-PROCEDURE",
                axisService.getName());

        ResultSet rs = null;
        try {
            rs = cs.executeQuery();
            if (rs.getMetaData().getColumnCount() == 0) {
                noResultSet = true;
            }
        } catch (SQLException e) {
            if (e.getMessage()
                    .indexOf("java.sql.CallableStatement.executeQuery() "
                            + "was called but no result set was returned. "
                            + "Use java.sql.CallableStatement.executeUpdate() for non-queries.") > -1) {
                noResultSet = true;
                cs.executeUpdate();
            } else {
                log.error("Error occured getting stored procedure result", e);
            }
        }

        //check for out parameters         
        OMElement result = queryElement.getFirstChildWithName(new QName("result"));
        String prefix = null;
        String resultElementNS = null;
        Query query = new Query(queryElement.getChildrenWithName(new QName("param")));
        if (result == null) {
            hasResponse = false;
        }

        if (hasResponse) {
            Result resultObj = new Result(result);
            resultElementNS = result.getAttributeValue(new QName("defaultNamespace"));
            if (resultElementNS == null || resultElementNS.trim().length() == 0) {
                resultElementNS = axisService.getTargetNamespace();
            }

            String columnDefalut = result.getAttributeValue(new QName("columnDefault"));
            OMFactory fac = OMAbstractFactory.getOMFactory();

            //get prefix for namespace
            HashMap namespacePrefixMap = null;
            HashMap queryLevelNamespaceMap = null;
            HashMap queryLevelPrefixMap = null;

            if (axisService.getParameterValue(DBConstants.NAMESPACE_PREFIX_MAP) != null) {
                namespacePrefixMap = (HashMap) axisService.getParameterValue(DBConstants.NAMESPACE_PREFIX_MAP);
                queryLevelNamespaceMap = (HashMap) axisService
                        .getParameterValue(DBConstants.QUERYLEVEL_NAMESPACE_MAP);
                queryLevelPrefixMap = (HashMap) axisService
                        .getParameterValue(DBConstants.QUERYLEVEL_PREFIX_MAP);

                prefix = (String) namespacePrefixMap.get(resultElementNS);
                if (prefix == null) {
                    prefix = DBConstants.RESULT_PREFIX + BeanUtil.getUniquePrefix();
                    namespacePrefixMap.put(resultElementNS, prefix);
                    queryLevelNamespaceMap.put(new Integer(queryLevel), resultElementNS);
                    queryLevelPrefixMap.put(new Integer(queryLevel), prefix);
                }
            } else {
                namespacePrefixMap = new HashMap();
                queryLevelNamespaceMap = new HashMap();
                queryLevelPrefixMap = new HashMap();

                prefix = DBConstants.RESULT_PREFIX + BeanUtil.getUniquePrefix();
                namespacePrefixMap.put(resultElementNS, prefix);
                queryLevelNamespaceMap.put(new Integer(queryLevel), resultElementNS);
                queryLevelPrefixMap.put(new Integer(queryLevel), prefix);

                axisService.addParameter(DBConstants.NAMESPACE_PREFIX_MAP, namespacePrefixMap);
                axisService.addParameter(DBConstants.QUERYLEVEL_NAMESPACE_MAP, queryLevelNamespaceMap);
                axisService.addParameter(DBConstants.QUERYLEVEL_PREFIX_MAP, queryLevelPrefixMap);
            }

            omNs = fac.createOMNamespace(resultElementNS, prefix);

            if (queryLevel > 0) {
                String previousNS = (String) queryLevelNamespaceMap.get(new Integer(queryLevel - 1));
                String previousNSPrefix = (String) queryLevelPrefixMap.get(new Integer(queryLevel - 1));
                omNs = fac.createOMNamespace(previousNS, previousNSPrefix);
                resultElement = fac.createOMElement(resultObj.getResultWrapper(), omNs);
            } else {
                resultElement = fac.createOMElement(resultObj.getResultWrapper(), omNs);
            }

            //put result elements into an array
            Iterator tmpElements = result.getChildElements();
            ArrayList tmpElementsArrayList = new ArrayList();
            while (tmpElements.hasNext()) {
                OMElement element = (OMElement) tmpElements.next();
                tmpElementsArrayList.add(element);
            }

            if (!noResultSet && rs != null) {

                while (rs.next()) {
                    HashMap elementValues = new HashMap();
                    int columnCount = rs.getMetaData().getColumnCount();

                    if (queryLevel > 0) {
                        omNs = fac.createOMNamespace(resultElementNS, prefix);
                    }

                    OMElement row = fac.createOMElement(resultObj.getRowName(), omNs);
                    if (resultObj.getRowName() == null) {
                        row = resultElement;
                    }
                    for (int i = 1; i <= columnCount; i++) {
                        String columnName = rs.getMetaData().getColumnLabel(i);
                        //Some databases return columns in different cases
                        columnName = columnName.toLowerCase();
                        String columnValue = rs.getString(columnName);
                        elementValues.put(columnName, columnValue);
                    }

                    boolean useAsParamToNextQuery = false;
                    for (int a = 0; a < resultObj.getDisplayColumnNames().length; a++) {
                        //can be one of 'element','attribute','text','link' or 'header'   
                        String outPutElementType = resultObj.getElementLocalNames()[a];

                        if (outPutElementType.equals("element") || outPutElementType.equals("attribute")) {
                            String displayTagName = resultObj.getDisplayColumnNames()[a];
                            String resultSetFieldName = resultObj.getResultSetColumnNames()[a];
                            resultSetFieldName = resultSetFieldName.toLowerCase();

                            // This means,the parameter is not part of the
                            // resultset. i.e. it is being passed from user's
                            // parameters.                        

                            if (useAsParamToNextQuery) {
                                elementValue = (String) params.get(resultSetFieldName);
                                elementValues.put(resultSetFieldName, elementValue);
                            } else {
                                elementValue = (String) elementValues.get(resultSetFieldName);
                            }

                            if (elementValue == null) {
                                //This could be a OUT parameter of a stored procedure
                                elementValue = setOutparameterValue(cs, query, resultSetFieldName);
                            }

                            if (outPutElementType.equals("element")) {
                                OMElement rowElement = fac.createOMElement(displayTagName, omNs);
                                rowElement.addChild(fac.createOMText(rowElement, elementValue));
                                row.addChild(rowElement);
                            } else if (outPutElementType.equals("attribute")) {
                                row.addAttribute(displayTagName, elementValue, omNs);
                            }
                        } else if (resultObj.getElementLocalNames()[a].equals("call-query")) {
                            OMElement element = (OMElement) tmpElementsArrayList.get(a);
                            OMElement rowElement = getRDBMSResult(element, axisService, elementValues,
                                    queryLevel + 1);
                            queryLevel = queryLevel - 1;
                            row.addChild(rowElement);
                        }
                    }
                    if (resultObj.getRowName() != null) {
                        resultElement.addChild(row);
                    }
                }
            } else {
                //No resultset, only out parameters are there.
                OMElement row = null;
                if (resultObj.getRowName() != null) {
                    //row name is OPTIONAL
                    row = fac.createOMElement(resultObj.getRowName(), omNs);
                }

                //if (resultObj.getRowName() == null) {
                //   row = resultElement;
                //}

                for (int a = 0; a < resultObj.getDisplayColumnNames().length; a++) {
                    if (resultObj.getElementLocalNames()[a].equals("element")) {
                        String displayTagName = resultObj.getDisplayColumnNames()[a];
                        String resultSetFieldName = resultObj.getResultSetColumnNames()[a];
                        elementValue = setOutparameterValue(cs, query, resultSetFieldName);

                        if (columnDefalut == null || columnDefalut.equals("element")) {
                            OMElement rowElement = fac.createOMElement(displayTagName, omNs);
                            rowElement.addChild(fac.createOMText(rowElement, elementValue));
                            if (row != null) {
                                row.addChild(rowElement);
                            } else {
                                resultElement.addChild(rowElement);
                            }

                        } else if (columnDefalut.equals("attribute")) {
                            if (row != null) {
                                row.addAttribute(displayTagName, elementValue, omNs);
                            } else {
                                resultElement.addAttribute(displayTagName, elementValue, omNs);
                            }
                        }
                    }
                }
                if (row != null) {
                    resultElement.addChild(row);
                }
            }
        }
    } catch (SQLException e) {
        log.error("Exception occurred while trying to execute the SQL statement : " + sqlQuery, e);
        throw new AxisFault("Exception occurred while trying to execute the SQL statement : " + sqlQuery, e);
    }

    finally {
        try {
            if (conn != null && queryLevel == 0) {
                conn.commit();
                conn.close();
            }
        } catch (SQLException e) {
            log.error(e.getMessage());
            throw new AxisFault("Exception occurred while trying to commit.", e);
        }
    }
    return resultElement;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserSuspension(java.lang.String, boolean)
 *///from w  w w.  j  av a2  s .  c o  m
public synchronized boolean modifyUserSuspension(final String userId, final boolean isSuspended)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserSuspension(final String userId, final boolean isSuspended) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", isSuspended);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{ CALL modifyUserSuspension(?, ?) }");
        stmt.setString(1, userId);
        stmt.setBoolean(2, isSuspended);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        int x = stmt.executeUpdate();

        if (DEBUG) {
            DEBUGGER.debug("Update: {}", x);
        }

        if (x == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:nl.nn.adapterframework.jdbc.JdbcQuerySenderBase.java

protected String executeOtherQuery(Connection connection, String correlationID, PreparedStatement statement,
        String message, ParameterResolutionContext prc, ParameterList newParamList) throws SenderException {
    ResultSet resultset = null;/*ww  w  .  j a  va  2s  .  c o  m*/
    try {
        int numRowsAffected = 0;
        if (StringUtils.isNotEmpty(getRowIdSessionKey())) {
            CallableStatement cstmt = getCallWithRowIdReturned(connection, correlationID, message);
            int ri = 1;
            if (prc != null && paramList != null) {
                ParameterValueList parameters = prc.getValues(newParamList);
                applyParameters(cstmt, parameters);
                ri = parameters.size() + 1;
            }
            cstmt.registerOutParameter(ri, Types.VARCHAR);
            log.debug(getLogPrefix() + "executing a SQL command");
            numRowsAffected = cstmt.executeUpdate();
            String rowId = cstmt.getString(ri);
            if (prc != null)
                prc.getSession().put(getRowIdSessionKey(), rowId);
        } else {
            log.debug(getLogPrefix() + "executing a SQL command");
            numRowsAffected = statement.executeUpdate();
        }
        if (StringUtils.isNotEmpty(getResultQuery())) {
            Statement resStmt = null;
            try {
                resStmt = connection.createStatement();
                log.debug("obtaining result from [" + getResultQuery() + "]");
                ResultSet rs = resStmt.executeQuery(getResultQuery());
                return getResult(rs);
            } finally {
                if (resStmt != null) {
                    resStmt.close();
                }
            }
        }
        if (getColumnsReturnedList() != null) {
            return getResult(getReturnedColumns(getColumnsReturnedList(), statement));
        }
        if (isScalar()) {
            return numRowsAffected + "";
        }
        return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
    } catch (SQLException sqle) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", sqle);
    } catch (JdbcException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (IOException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (JMSException e) {
        throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "got exception evaluating parameters", e);
    } finally {
        try {
            if (resultset != null) {
                resultset.close();
            }
        } catch (SQLException e) {
            log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
        }
    }
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserEmail(java.lang.String, java.lang.String)
 *///from ww w. j av  a 2 s.c  o  m
public synchronized boolean modifyUserEmail(final String userId, final String value)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserEmail(final String userId, final String value) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", value);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateUserEmail(?, ?) }");
        stmt.setString(1, userId);
        stmt.setString(2, value);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyOlrLock(java.lang.String, boolean)
 *//* w w w .  j a va 2s.  c o m*/
public synchronized boolean modifyOlrLock(final String userId, final boolean isLocked)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyOlrLock(final String userId, final boolean value) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", isLocked);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateOlrLock(?, ?,}");
        stmt.setString(1, userId);
        stmt.setBoolean(2, isLocked);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserPassword(java.lang.String, java.lang.String)
 *//* w  ww.j a v a2s .  co m*/
public synchronized boolean modifyUserPassword(final String userId, final String newPass)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserPassword(final String userId, final String newPass) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("userId: {}", userId);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateUserPassword(?, ?) }");
        stmt.setString(1, userId);
        stmt.setString(3, newPass);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserLock(java.lang.String, boolean, int)
 *//*from   w  w  w. j a v a 2s.  com*/
public synchronized boolean modifyUserLock(final String userId, final boolean isLocked, final int increment)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserLock(final String userId, final boolean int, final boolean increment) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", isLocked);
        DEBUGGER.debug("Value: {}", increment);
    }

    Connection sqlConn = null;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        if (isLocked) {
            stmt = sqlConn.prepareCall("{ CALL lockUserAccount(?) }");
            stmt.setString(1, userId);
        } else {
            stmt = sqlConn.prepareCall("{ CALL incrementLockCount(?) }");
            stmt.setString(1, userId);
        }

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        return (stmt.executeUpdate() == 0);
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserGroups(java.lang.String, java.lang.Object[])
 *//*from w  ww. ja v a  2 s  .  com*/
public synchronized boolean modifyUserGroups(final String userId, final Object[] values)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserGroups(final String userId, final Object[] values) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Value: {}", values);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateUserGroups(?, ?,}");
        stmt.setString(1, userId);
        stmt.setString(2, Arrays.toString(values));

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyOtpSecret(java.lang.String, boolean, java.lang.String)
 *//*from  ww w  .java 2s.c om*/
public synchronized boolean modifyOtpSecret(final String userId, final boolean addSecret, final String secret)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyOtpSecret(final String userId, final boolean addSecret, final String secret) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("userId: {}", userId);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        if (addSecret) {
            stmt = sqlConn.prepareCall("{ CALL addUserSecret(?, ?) }");
            stmt.setString(1, userId);
            stmt.setString(2, secret);
        } else {
            stmt = sqlConn.prepareCall("{ CALL removeUserSecret(?) }");
            stmt.setString(1, userId);
        }

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#modifyUserContact(java.lang.String, java.util.List)
 *//*from   w  w w .  j  a  v  a  2s  .  c om*/
public synchronized boolean modifyUserContact(final String userId, final List<String> values)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#modifyUserContact(final String userId, final List<String> values) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userId);
        DEBUGGER.debug("Values: {}", values);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        // first make sure the existing password is proper
        // then make sure the new password doesnt match the existing password
        stmt = sqlConn.prepareCall("{ CALL updateUserContact(?, ?, ?) }");
        stmt.setString(1, userId);
        stmt.setString(2, values.get(0));
        stmt.setString(2, values.get(1));

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.executeUpdate() == 1) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}