[KYUUBI #7160] Use single try-with-resources blocks in docs example
Gets rid of the nested try-with-resources blocks. Improves legibility slightly. ### Why are the changes needed? Make the example code just a bit nicer. ### How was this patch tested? It still compiles. I created a simple (maven) project using only these two java files. ### Was this patch authored or co-authored using generative AI tooling? No Closes #7160 from jagij/patch-1. Closes #7160 9d9624841 [Jan Willem] single try-with-resources blocks Authored-by: Jan Willem <jan.willem.ps@gmail.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
parent
d2cfc871be
commit
0b4b5cabc4
@ -48,13 +48,12 @@ public class KyuubiJDBC {
|
||||
private static String kyuubiJdbcUrl = "jdbc:kyuubi://localhost:10009/default;";
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
try (ResultSet rs = stmt.executeQuery("show databases")) {
|
||||
while (rs.next()) {
|
||||
System.out.println(rs.getString(1));
|
||||
}
|
||||
}
|
||||
try (
|
||||
Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("show databases")) {
|
||||
while (rs.next()) {
|
||||
System.out.println(rs.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,13 +80,12 @@ public class KyuubiJDBCDemo {
|
||||
String clientKeytab = args[1]; // Keytab file location
|
||||
String serverPrincipal = args[2]; // Kerberos principal used by Kyuubi Server
|
||||
String kyuubiJdbcUrl = String.format(kyuubiJdbcUrlTemplate, clientPrincipal, clientKeytab, serverPrincipal);
|
||||
try (Connection conn = DriverManager.getConnection(kyuubiJdbcUrl)) {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
try (ResultSet rs = stmt.executeQuery("show databases")) {
|
||||
while (rs.next()) {
|
||||
System.out.println(rs.getString(1));
|
||||
}
|
||||
}
|
||||
try (
|
||||
Connection conn = DriverManager.getConnection(kyuubiJdbcUrl);
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("show databases")) {
|
||||
while (rs.next()) {
|
||||
System.out.println(rs.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user