java - 通过存储过程的多个结果集输出进行查询以获取列的值

标签 java sql stored-procedures tomcat7

存储过程返回三个结果集。我想要第三个结果集中的列的值。我想循环遍历结果集并获取该列的值。

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/

相关文章:

php - 通过运行并集和交集组合 5 个 SQL 查询的结果

TSQL:可以根据环境引用不同的数据库吗?

sql-server - SQL 服务器 : using MERGE statement to update two tables

java - Simple-XML - 如何序列化集合中的派生类?

java - spring data 是否使用新的 MongoDB Bulk API 进行批量操作?

java - Eclipse:无法找到或加载主类

mysql - 在 if/else block 内创建表的问题

java - 使用 JNI 时 CryptUnprotectData 返回 false

sql - 如何在 Access SQL 中使用反余弦 (ACOS)

无限循环中的Sql游标。这段代码有什么问题?