假设有一些 Oracle PL/SQL 过程,它接收IN参数并返回OUT游标参数。我有一个执行此过程的 jdbc 代码:
DataSource dataSource;
//datasource was set
CallableStatement statement = null;
ResultSet result = null;
ResultSet secondaryResult = null;
Connection connection = null;
try {
connection = dataSource.getConnection();
statement = connection.prepareCall("{? = call pl_sql_func(?)}");
statement.registerOutParameter(1, OracleTypes.CURSOR);
statement.setString(2,"param");
// !
secondaryResult = statement.executeQuery();
secondaryResult.close();
result = (ResultSet) statement.getObject(1);
while(result.next()){
//get some data
}
} catch (Exception ex){
}
finally{
//closing statement, result, secondaryResult and connection
}
我尝试执行这段代码,发现 secondaryResult 没有数据,但 result 有。很正常,但是谁能解释
1)statement.executeQuery()
真正产生什么?
2) 当语句产生过程调用时,返回的ResultSet 可以包含数据吗?还是总是空的?
PSPossible 优化不是这个问题的目标。我希望按原样解释代码。