0

我正在用 Java 执行存储过程。其中一个过程返回多行。

int haveResults = Param.callableStatement.executeUpdate();
System.out.println(haveResults);
if (haveResults > 0) {
    System.out.println("I have results"); //This statement is printed
    ResultSet rs = Param.callableStatement.getResultSet();
    while (rs.next()) { //This is where I am getting error:NullPointerException
        //If I comment 'while(rs.next())' then code is giving output but then it can't handle multiple rows
        itr1 = listOutParam.iterator();
        while (itr1.hasNext()) {
            Object obj = null;
            obj = ParameterGetter.getParameter(itr1.next().toString(), counter1);
            list.add(obj);
            counter1++;
        }
        System.out.println(list.toString());
        list1.add(list);
        counter1 = counter2;
    }
}
}

我尝试使用 execute() 但如果返回 false 值,表明该过程未成功执行。

4

1 回答 1

1

如果您想ResultSet从 a中检索 aCallableStatement您需要使用execute()而不是executeUpdate()

if (Param.callableStatement.execute()) {
     ResultSet rs = Param.callableStatement.getResultSet();
     ...
}
于 2016-04-07T07:23:59.677 回答