之後使用CallableStatement檢索ResultSet我需要多次調用存儲過程,並使用executeBatch()
來實現此目的。每次調用都應該返回表格的結果,但我無法訪問此結果。接下來的代碼工作正常:如預期executeBatch()
callableStatement.setString(1, "foo");
callableStatement.setString(2, "bar");
callableStatement.execute();
resultSet = callableStatement.getResultSet();
但接下來的代碼不起作用:
for (String str : strings) {
callableStatement.setString(1, str);
callableStatement.setString(2, "bar");
callableStatement.addBatch();
}
callableStatement.executeBatch();
resultSet = callableStatement.getResultSet(); // returns null
我已經嘗試過提取的ResultSet,但沒有成功之前調用callableStatement.getUpdateCount()
和callableStatement.getMoreResults()
。
你的var應該是'callableStatement'還是'cs'?我認爲你的實際代碼不是這樣嗎?如果是這樣,那就是你的問題! – wmorrison365
@ wmorrison365,當然,這是一個錯字。這不是實際的代碼,但足以找出我使用的兩種方法之間的差異。 – bsiamionau