diff --git a/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponse.java b/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponse.java index 6bcb21d..24d85ca 100644 --- a/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponse.java +++ b/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponse.java @@ -35,15 +35,17 @@ public static ResponseData execute(String url, String query, Logger logger) thro logger.info("Response data is empty, response length: " + resultStringBuilder.length()); throw new Exception("Response data is empty..."); } - statement.close(); - resultSet.close(); return new ResponseData(resultStringBuilder.toString(), value); } catch (Exception e) { - Objects.requireNonNull(statement).close(); - Objects.requireNonNull(resultSet).close(); String errorMessage = ExceptionUtils.getStackTrace(e); logger.info(errorMessage); throw new Exception("Error occurred while executing the given query: " + errorMessage); } + finally { + if(statement != null) + statement.close(); + if(resultSet != null) + resultSet.close(); + } } } diff --git a/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponseData.java b/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponseData.java index 4dc2f81..e2c6685 100644 --- a/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponseData.java +++ b/snowflakedb_queries/src/main/java/com/testsigma/addons/util/FetchResponseData.java @@ -40,14 +40,16 @@ public static String execute(String url, String query, Logger logger) throws Exc } resultStringBuilder.append("\n"); } - statement.close(); - resultSet.close(); return resultStringBuilder.toString(); } catch (Exception e){ - Objects.requireNonNull(statement).close(); - Objects.requireNonNull(resultSet).close(); throw new Exception(e); } + finally { + if(statement != null) + statement.close(); + if(resultSet != null) + resultSet.close(); + } } }