JDBC 可调用语句 returns 空结果集,如果在 SP 中使用了临时表
JDBC callable statement returns null resultset , if temp tabel is used in SP
在这里,很简单,例如我如何使用 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();
它对所有 SP 都工作正常。
但是如果在 SP 中使用了 temp table 那么它 returns null Resultset.
通过添加此代码解决了我的问题
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();
}
参考:Here
在这里,很简单,例如我如何使用 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();
它对所有 SP 都工作正常。 但是如果在 SP 中使用了 temp table 那么它 returns null Resultset.
通过添加此代码解决了我的问题
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();
}
参考:Here