Skip to content

Commit

Permalink
Changed loop, added try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ETHenzlere committed Dec 5, 2023
1 parent 26b9c11 commit 53df7b7
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,31 @@ public abstract class GenericQuery extends Procedure {

protected static final Logger LOG = LoggerFactory.getLogger(GenericQuery.class);

/** Execution method with parameters. */
/** Execution method with parameters. */
public void run(Connection conn, List<Object> params) throws SQLException {

try (PreparedStatement stmt = getStatement(conn, params)) {

// False for UPDATE, INSERT, DELETE queries
boolean hasResultSet = stmt.execute();

while (true) {
if (hasResultSet) {
try (ResultSet rs = stmt.getResultSet()) {
while (rs.next()) {
// do nothing
do {
try (ResultSet rs = stmt.getResultSet()) {
while (rs.next()) {
// do nothing
}
} catch (Exception resultException){
resultException.printStackTrace();
throw new RuntimeException("Could not retrieve ResultSet");
}
}
} while(stmt.getMoreResults());
} else {
if (stmt.getUpdateCount() == -1) {
break;
}
// Case for UPDATE, INSERT, DELETE queries
// do nothing
}
hasResultSet = stmt.getMoreResults();
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error when trying to execute statement");
}

conn.commit();
}

Expand Down

0 comments on commit 53df7b7

Please sign in to comment.