diff --git jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index bb2b695..e0248f1 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -959,15 +959,13 @@ public String getSchema() throws SQLException { if (isClosed) { throw new SQLException("Connection is closed"); } - Statement stmt = createStatement(); - ResultSet res = stmt.executeQuery("SELECT current_database()"); - if (!res.next()) { - throw new SQLException("Failed to get schema information"); + try (Statement stmt = createStatement(); + ResultSet res = stmt.executeQuery("SELECT current_database()")) { + if (!res.next()) { + throw new SQLException("Failed to get schema information"); + } + return res.getString(1); } - String schemaName = res.getString(1); - res.close(); - stmt.close(); - return schemaName; } /*