Search code examples
javasql-serverjdbccallable-statement

JDBC callable statement returns null resultset , if temp tabel is used in SP


Here, is simple e.g. of How I'm using callablestatement

Connection con = getConnection();
CallableStatement call = con.prepareCall("{call SpName(?, ?)}");
call .setObject(1, params[0]);
call .setObject(2, params[1]);
call .execute();
ResultSet rs = call .getResultSet();

It's working fine for all SP. But if there is temp table used in SP then it returns null Resultset.


Solution

  • Solved my problem by adding this code

    while (true) {
        rs = cstmt.getResultSet();
        int updateCount = cstmt.getUpdateCount();
        LogWriter.write(" Update count " + updateCount);
        if (rs == null && updateCount == -1) {
            break;
        }
        if (rs != null) {
            // process the result set
        } else {
            System.out.println("Update count = " + cstmt.getUpdateCount());
        }
        cstmt.getMoreResults();
    }
    

    Reference: Here