/** * Execute a stored procedure that updates data * * @param statementScope - the request scope * @param conn - the database connection * @param sql - the SQL to call the procedure * @param parameters - the parameters for the procedure * @return - the rows impacted by the procedure * @throws SQLException - if the procedure fails */ public int executeUpdateProcedure( StatementScope statementScope, Connection conn, String sql, Object[] parameters) throws SQLException { ErrorContext errorContext = statementScope.getErrorContext(); errorContext.setActivity("executing update procedure"); errorContext.setObjectId(sql); CallableStatement cs = null; setupResultObjectFactory(statementScope); int rows = 0; try { errorContext.setMoreInfo("Check the SQL Statement (preparation failed)."); cs = prepareCall(statementScope.getSession(), conn, sql); setStatementTimeout(statementScope.getStatement(), cs); ParameterMap parameterMap = statementScope.getParameterMap(); ParameterMapping[] mappings = parameterMap.getParameterMappings(); errorContext.setMoreInfo("Check the output parameters (register output parameters failed)."); registerOutputParameters(cs, mappings); errorContext.setMoreInfo("Check the parameters (set parameters failed)."); parameterMap.setParameters(statementScope, cs, parameters); errorContext.setMoreInfo("Check the statement (update procedure failed)."); cs.execute(); rows = cs.getUpdateCount(); errorContext.setMoreInfo( "Check the output parameters (retrieval of output parameters failed)."); retrieveOutputParameters(statementScope, cs, mappings, parameters, null); } finally { closeStatement(statementScope.getSession(), cs); } return rows; }
/** * Execute a stored procedure * * @param statementScope - the request scope * @param conn - the database connection * @param sql - the sql to call the procedure * @param parameters - the parameters for the procedure * @param skipResults - the number of results to skip * @param maxResults - the maximum number of results to return * @param callback - a row handler for processing the results * @throws SQLException - if the procedure fails */ public void executeQueryProcedure( StatementScope statementScope, Connection conn, String sql, Object[] parameters, int skipResults, int maxResults, RowHandlerCallback callback) throws SQLException { ErrorContext errorContext = statementScope.getErrorContext(); errorContext.setActivity("executing query procedure"); errorContext.setObjectId(sql); CallableStatement cs = null; ResultSet rs = null; setupResultObjectFactory(statementScope); try { errorContext.setMoreInfo("Check the SQL Statement (preparation failed)."); Integer rsType = statementScope.getStatement().getResultSetType(); if (rsType != null) { cs = prepareCall(statementScope.getSession(), conn, sql, rsType); } else { cs = prepareCall(statementScope.getSession(), conn, sql); } setStatementTimeout(statementScope.getStatement(), cs); Integer fetchSize = statementScope.getStatement().getFetchSize(); if (fetchSize != null) { cs.setFetchSize(fetchSize.intValue()); } ParameterMap parameterMap = statementScope.getParameterMap(); ParameterMapping[] mappings = parameterMap.getParameterMappings(); errorContext.setMoreInfo("Check the output parameters (register output parameters failed)."); registerOutputParameters(cs, mappings); errorContext.setMoreInfo("Check the parameters (set parameters failed)."); parameterMap.setParameters(statementScope, cs, parameters); errorContext.setMoreInfo("Check the statement (update procedure failed)."); cs.execute(); errorContext.setMoreInfo("Check the results (failed to retrieve results)."); // Begin ResultSet Handling rs = handleMultipleResults(cs, statementScope, skipResults, maxResults, callback); // End ResultSet Handling errorContext.setMoreInfo( "Check the output parameters (retrieval of output parameters failed)."); retrieveOutputParameters(statementScope, cs, mappings, parameters, callback); } finally { try { closeResultSet(rs); } finally { closeStatement(statementScope.getSession(), cs); } } }