Java Spring JDBC Oracle Stored Procedure returns null [duplicate]
Possible Duplicate:
Spring's Stored Procedure - results coming back from procedure always empty.
I have the following code and although I know the call should result in contents I always get back an empty resultset can anyone suggest why?
ParameterizedRowMapper<ExamPaper> mapper = new ParameterizedRowMapper<ExamPaper>() {
public ExamPaper mapRow(ResultSet rs, int rowNum) throws SQLException {
logger.info("in the row mapper with"+rs.toString());
logger.info("in the row mapper with x no of rows " +rowNum);
ExamPaper examPaper = new ExamPaper();
examPaper.setCampus(rs.getString("campus"));
examPaper.setTitle(rs.getString("title"));
examPaper.setPaper(rs.getString("paper"));
examPaper.setCode(rs.getString("code"));
examPaper.year.add(rs.getString("year"));
examPaper.semester.add(rs.getString("semester"));
return examPaper;
}
};
Map params = new HashMap();
params.put("ic_search_string","fluid");
params.put("ic_location_flag", "unmc");
logger.info("calling stored procedure");
OracleStoredProcedure storedProcedure = new OracleStoredProcedure(getDataSource(),"pkg_exam_papers.p_get_exam_papers",logger, mapper);
Map results = storedProcedure.execute(params);
logger.info(results.size());
public class OracleStoredProcedure extends StoredProcedure
{
private Log logger;
public OracleStoredProcedure(DataSource dataSource,String storedProcedureName, Log logger,ParameterizedRowMapper mapper)
{
super();
this.logger = logger;
setDataSource(dataSource);
setFunction(false);
setSql(storedProcedureName)
declareParameter(new SqlPa开发者_如何学JAVArameter("ic_search_string", OracleTypes.VARCHAR));
declareParameter(new SqlParameter("ic_location_flag", OracleTypes.VARCHAR));
declareParameter(new SqlOutParameter("orc_results", OracleTypes.CURSOR, mapper));
declareParameter(new SqlOutParameter("on_errcode", OracleTypes.INTEGER));
declareParameter(new SqlOutParameter("oc_errmess", OracleTypes.CHAR));
compile();
}
public Map execute(Map parameters)
{
Map out = new HashMap();
try
{
out = super.execute(parameters);
}
catch (NullPointerException nullPointerException)
{
logger.error("Exception when executing stored procedure: " + nullPointerException.getMessage());
}
catch(Exception exception)
{
logger.error("Exception when executing stored procedure: " + exception.getMessage());
}
return out;
}
}
At first glance it looks ok. Have you tried running the stored proc in sqlDeveloper with the same parameters against the same database to make sure it actually returns results?
I think your questioned is answered by another similar one from a year ago: Spring's Stored Procedure - results coming back from procedure always empty
精彩评论