Hi Folks,
I'm also having difficulty getting started with stored procedures.
In my case, the DB is Oracle. The arguments are
- in - String
in - String
out - ResultSet
in - Integer
Presently, the SP is invoked through
JDBC in the following manner:
Code:
// call is CallableStatement, conn is Connection
call = conn.prepareCall("{call pkg_product.p_get_by_uid (?,?,?,?)}");
call.setString(1, uid);
call.setString(2, companyId);
call.registerOutParameter(3, OracleTypes.CURSOR);
call.setInt(4, MyConstants.RESULTSET_TYPE_WEB);
call.execute();
rs = (ResultSet) call.getObject(3);
I'm trying to invoke it through String's StoredProcedure mechanism
like this:
Code:
public GetProdByUid(DataSource ds) {
super(ds, SP_NAME);
setParameters();
}
private void setParameters() {
declareParameter(new SqlParameter(PARAM_UID_LIST, Types.VARCHAR));
declareParameter(new SqlParameter(PARAM_COMPANY_ID, Types.VARCHAR));
declareParameter(new SqlReturnResultSet(PARAM_PRODUCT_RS, new ProductRowMapper()));
declareParameter(new SqlParameter(PARAM_RESULT_TYPE, Types.INTEGER));
compile();
}
public ProductResultBean getProdByUid(String uid) {
Map inputMap = new HashMap(5);
inputMap.put(PARAM_UID_LIST, uid);
inputMap.put(PARAM_COMPANY_ID, null);
inputMap.put(PARAM_PRODUCT_RS, new Integer(OracleTypes.CURSOR));
inputMap.put(PARAM_RESULT_TYPE, new Integer(RMSConstants.RESULTSET_TYPE_WEB));
Map outputMap = execute(inputMap);
List productList = (List) outputMap.get(PARAM_PRODUCT_RS);
ProductResultBean result = (ProductResultBean) productList.get(0);
return result;
}
I get the following error:
org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar
[{call pkg_product.p_get_by_uid(?, ?, ?)}];
The declareParameter does not seem to count the SqlReturnResultSet
as a parameter. I've tried moving the out-parameter to the beginning,
which seems to have worked for others. But I still get the error. I
suspect the SP on the Oracle side wants four parameters, but the
Spring base class is only registering three. Any hints?
Thanks,
- Paul