存储过程返回三个结果集。我想要第三个结果集中的列的值。我想循环遍历结果集并获取该列的值。
Ex: lets say SP returns three tables.
table 1:
Sno,Col_val1,Col_Val 2
table2:
Sno,Col_val11,Col_Val 22
table 3:
Sno,Col_val111,Col_Val 222
以上是SP的输出。
我想要 Col_val111 的值。如何在 java 中执行以下操作?
最佳答案
这可能会有所帮助。给出的例子是 here但在链接失效的情况下转载如下:
CallableStatement cstmt;
ResultSet rs;
int i;
String s;
...
cstmt.execute(); // Call the stored procedure
rs = cstmt.getResultSet(); // Get the first result set
while (rs.next()) { // Position the cursor
i = rs.getInt(1); // Retrieve current result set value
System.out.println("Value from first result set = " + i);
// Print the value
}
cstmt.getMoreResults(); // Point to the second result set
// and close the first result set
rs = cstmt.getResultSet(); // Get the second result set
while (rs.next()) { // Position the cursor
s = rs.getString(1); // Retrieve current result set value
System.out.println("Value from second result set = " + s);
// Print the value
}
rs.close(); // Close the result set
cstmt.close(); // Close the statement
关于java - 通过存储过程的多个结果集输出进行查询以获取列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33482563/