Java Spring JDBC Oracle 存储过程返回 null
我有以下代码,虽然我知道调用应该产生内容,但我总是返回一个空结果集,任何人都可以建议为什么吗?
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 SqlParameter("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;
}
}
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 SqlParameter("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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
乍一看还不错。您是否尝试过在 sqlDeveloper 中使用相同的参数针对同一数据库运行存储过程以确保它实际返回结果?
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?
我认为一年前另一个类似的问题回答了您的问题: Spring 的存储过程 - 从过程返回的结果始终为空
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