Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SivasaiPodugu committed Feb 15, 2024
1 parent a6b130b commit 9b3d7d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class FetchResponse {
public static ResponseData execute(String url, String query, Logger logger) throws Exception {
StringBuilder resultStringBuilder = new StringBuilder();
String value = "";
Statement statement = null;
ResultSet resultSet = null;
try {

Statement statement = SnowflakeDBConnection.getConnection(url);
statement = SnowflakeDBConnection.getConnection(url);
logger.info("Successfully set JDBC_QUERY_RESULT_FORMAT='JSON'");
logger.info("Executing query: " + query);
ResultSet resultSet;
resultSet = statement.executeQuery(query);
resultStringBuilder = new StringBuilder();
if (resultSet.next()) {
Expand All @@ -39,6 +39,8 @@ public static ResponseData execute(String url, String query, Logger logger) thro
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Objects;

public class FetchResponseData {
public static String execute(String url, String query, Logger logger) throws Exception {
Statement statement = null;
ResultSet resultSet = null;
try{
StringBuilder resultStringBuilder = null;
Statement statement = SnowflakeDBConnection.getConnection(url);
statement = SnowflakeDBConnection.getConnection(url);
logger.info("Successfully set JDBC_QUERY_RESULT_FORMAT='JSON'");
logger.info("Executing query: " + query);
ResultSet resultSet = statement.executeQuery(query);
resultSet = statement.executeQuery(query);
resultStringBuilder = new StringBuilder();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
Expand Down Expand Up @@ -42,6 +45,8 @@ public static String execute(String url, String query, Logger logger) throws Exc
return resultStringBuilder.toString();
}
catch (Exception e){
Objects.requireNonNull(statement).close();
Objects.requireNonNull(resultSet).close();
throw new Exception(e);
}
}
Expand Down

0 comments on commit 9b3d7d5

Please sign in to comment.