Vinod Vishwakarma
Vinod Vishwakarma

Reputation: 33

ResultSet is not null still resultset.next() returning false

I'm trying to access a procedure which returns a cursor, my resultset is not null still resultset.next() is returning false and that's why control is not entering into while, please see below mention my procedure and my java code and help me on this.

this is my procedure:

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;

/ and this is my java code:

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"));

Upvotes: 0

Views: 643

Answers (2)

Tech Enthusiast
Tech Enthusiast

Reputation: 287

Dont call resultSet.next() unnecessarily because as per documentation :- http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/sql/ResultSet.java#ResultSet.next%28%29. If you call

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

it will move cursor to next row. and again calling

while(resultSet.next()){

is actually pointed to your second row. So you have only one record returned in resultset.

Upvotes: 1

karthik
karthik

Reputation: 17

1.Can you make sure your database is returning data

2.Can you check with resultSet= (OracleResultSet)cs.getCursor(2); Maybe remove this particular line??

Hope this helps!!

Upvotes: 0

Related Questions