ResultSet不为null仍然resultset.next()返回false

时间:2016-12-12 11:51:20

标签: java resultset

我试图访问一个返回游标的过程,我的结果集不为null仍然是resultset.next()返回false,这就是为什么控件没有进入的时候,请参阅下面的提到我的程序和我的java代码,并帮助我。

这是我的程序:

PROCEDURE get_app_biz_summary (p_application_name_i   IN     VARCHAR2,
                               p_summary_o               OUT SYS_REFCURSOR) IS BEGIN    IF p_application_name_i = 'ALL'    THEN
      OPEN p_summary_o FOR
           SELECT application_name,
                  creation_date,
                  SUM (success_count) success,
                  SUM (error_count) "error",
                  SUM (warning_count) warning
             FROM xxcss_sfm_app_biz_summary
            WHERE 1 = 1 AND creation_date >= SYSDATE - 4
         GROUP BY application_name, creation_date;    ELSE
      OPEN p_summary_o FOR
           SELECT application_name,
                  biz_process_name,
                  creation_date,
                  SUM (success_count) success,
                  SUM (error_count) "error",
                  SUM (warning_count) warning
             FROM xxcss_sfm_app_biz_summary
            WHERE application_name =
                     NVL (p_application_name_i, application_name)
                  AND creation_date >= SYSDATE - 4
         GROUP BY application_name, biz_process_name, creation_date;    END IF; END get_app_biz_summary;

END XXCSS_ORDER_STATUS_PKG;

/ 这是我的java代码:

try {
            OracleCallableStatement cs = (OracleCallableStatement)jdbcTemplate
        //  CallableStatement cs=jdbcTemplate
                    .getDataSource()
                    .getConnection()
                    .prepareCall(
                            "{call APPS.XXCSS_ORDER_STATUS_PKG.GET_APP_BIZ_SUMMARY(?,?)}");

            cs.setString(1, appName);
            cs.registerOutParameter(2, OracleTypes.CURSOR);
            cs.execute();
            resultSet= (OracleResultSet)cs.getCursor(2);
            if(resultSet==null )
                System.out.println("resultset null...."); // resultset is not null
            System.out.println(resultSet.next()); // its returning false
            while(resultSet.next()){
            System.out.println("in while");
                IBSave ibSave=new IBSave();
                ibSave.setApplicationName(resultSet.getString("APPLICATION_NAME"));

2 个答案:

答案 0 :(得分:1)

不要不必要地调用resultSet.next()因为根据文档: - http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/sql/ResultSet.java#ResultSet.next%28%29。 如果你打电话

proc

它会将光标移动到下一行。 并再次致电

System.out.println(resultSet.next()); // its returning false

实际上是指向你的第二行。因此,结果集中只返回了一条记录。

答案 1 :(得分:0)

1.您可以确保您的数据库正在返回数据

2.您可以查看resultSet= (OracleResultSet)cs.getCursor(2); 也许删除这个特定的行??

希望这会有所帮助!!