Hello,
I have a stored procedure in Sybase 12.5 that does some updates and returns 5 ResultSets. I’ve extended the StoredProcedure class and declared the parameters as shown in the examples I’ve seen. However, I was still unable to retrieve the ResultSets. After doing some debugging into the JdbcTemplate class, it seems that the call to cs.execute() only checks the return value once. In my case the first thing to be returned is an update count. So, unless a ResultSet is the first thing to be returned from a stored procedure, the doInCallableStatement () method won’t extract the ResultSets.
I’ve made some changes to the doInCallableStatement method to have it check the updateCount and the return value in an attempt to correct the problem. See the code below.
Am I missing something or is this a bug in the JdbcTemplate code?
Thanks,
Jeremy
Code:public Map call(CallableStatementCreator csc, final List declaredParameters) throws DataAccessException { return (Map) execute(csc, new CallableStatementCallback() { public Object doInCallableStatement(CallableStatement cs) throws SQLException { boolean retVal = cs.execute(); int updateCount = cs.getUpdateCount(); if (logger.isDebugEnabled()) { logger.debug("CallableStatement.execute returned [" + retVal + "]"); logger.debug("CallableStatement.getUpdateCount returned [" + updateCount + "]"); } Map returnedResults = new HashMap(); if (retVal || (updateCount != -1)) { returnedResults.putAll(extractReturnedResultSets(cs, declaredParameters, updateCount)); } returnedResults.putAll(extractOutputParameters(cs, declaredParameters)); return returnedResults; } }); } protected Map extractReturnedResultSets(CallableStatement cs, List parameters, int updateCount) throws SQLException { Map returnedResults = new HashMap(); int rsIndex = 0; boolean moreResults = false; do { if(updateCount == -1) { Object param = null; while(parameters != null && parameters.size() > rsIndex && !(param instanceof SqlReturnResultSet)) { param = parameters.get(rsIndex); rsIndex++; } if (param instanceof SqlReturnResultSet) { SqlReturnResultSet rsParam = (SqlReturnResultSet) param; returnedResults.putAll(processResultSet(cs.getResultSet(), rsParam)); } else { logger.warn("ResultSet returned from stored procedure but a corresponding " + "SqlReturnResultSet parameter was not declared"); } } moreResults = cs.getMoreResults(); updateCount = cs.getUpdateCount(); } while (moreResults || updateCount != -1); return returnedResults; }


Reply With Quote