Java Spring JDBC Oracle 存储过程返回 null

发布于 2024-10-17 06:32:03 字数 2582 浏览 1 评论 0原文

可能的重复:
Spring 的存储过程 - 从过程返回的结果始终为空。

我有以下代码,虽然我知道调用应该产生内容,但我总是返回一个空结果集,任何人都可以建议为什么吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不甘平庸 2024-10-24 06:32:03

乍一看还不错。您是否尝试过在 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?

简单 2024-10-24 06:32:03

我认为一年前另一个类似的问题回答了您的问题: 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文