From 0b4b5cabc468dde2bc92d3ca3c560fd2b77e6dc2 Mon Sep 17 00:00:00 2001 From: Jan Willem Date: Mon, 4 Aug 2025 11:26:20 +0800 Subject: [PATCH] [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 Signed-off-by: Cheng Pan --- docs/quick_start/quick_start_with_jdbc.md | 26 +++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/quick_start/quick_start_with_jdbc.md b/docs/quick_start/quick_start_with_jdbc.md index abd4fbec4..c0344db22 100644 --- a/docs/quick_start/quick_start_with_jdbc.md +++ b/docs/quick_start/quick_start_with_jdbc.md @@ -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)); } } }