-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathhandling-complex-statements_1.java
More file actions
28 lines (28 loc) · 1.05 KB
/
handling-complex-statements_1.java
File metadata and controls
28 lines (28 loc) · 1.05 KB
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 executeComplexStatement(Connection con) {
try (Statement stmt = con.createStatement();) {
String sqlStringWithUnknownResults = "{call dbo.uspGetEmployeeManagers(50)}; SELECT TOP 10 * FROM Person.Contact";
boolean results = stmt.execute(sqlStringWithUnknownResults);
int count = 0;
do {
if (results) {
ResultSet rs = stmt.getResultSet();
System.out.println("Result set data displayed here.");
}
else {
count = stmt.getUpdateCount();
if (count >= 0) {
System.out.println("DDL or update data displayed here.");
}
else {
System.out.println("No more results to process.");
}
}
results = stmt.getMoreResults();
}
while (results || count != -1);
}
// Handle any errors that may have occurred.
catch (SQLException e) {
e.printStackTrace();
}
}