forked from MicrosoftDocs/sql-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-multiple-result-sets_1.java
More file actions
28 lines (25 loc) · 954 Bytes
/
using-multiple-result-sets_1.java
File metadata and controls
28 lines (25 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public static void executeStatement(Connection con) {
try (Statement stmt = con.createStatement();) {
String SQL = "SELECT TOP 10 * FROM Person.Contact; SELECT TOP 20 * FROM Person.Contact";
boolean results = stmt.execute(SQL);
int rsCount = 0;
// Loop through the available result sets.
do {
if (results) {
ResultSet rs = stmt.getResultSet();
rsCount++;
// Show data from the result set.
System.out.println("RESULT SET #" + rsCount);
while (rs.next()) {
System.out.println(rs.getString("LastName") + ", " + rs.getString("FirstName"));
}
}
System.out.println();
results = stmt.getMoreResults();
} while (results);
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
}