private void closeStatementIfNeeded() throws SQLException {
    try {
      if (stmtHandle.isPresent()) {
        TCloseOperationReq closeReq = new TCloseOperationReq(stmtHandle.get());
        TCloseOperationResp closeResp = client.CloseOperation(closeReq);
        if (!checkInvalidOperationHandle(closeResp)) {
          Utils.verifySuccessWithInfo(closeResp.getStatus());
        }
      }
    } catch (SQLException e) {
      throw e;
    } catch (TApplicationException tae) {
      String errorMsg = "Failed to close statement";
      if (tae.getType() == TApplicationException.BAD_SEQUENCE_ID) {
        errorMsg = "Failed to close statement. Mismatch thrift sequence id. A previous call to the Thrift library"
            + " failed and now position within the input stream is lost. Please enable verbose error logging and"
            + " check the status of previous calls.";
      }
      throw new SQLException(errorMsg, "08S01", tae);
    } catch (Exception e) {
      throw new SQLException("Failed to close statement", "08S01", e);
    } finally {
      stmtHandle = Optional.empty();
    }
  }
Closes the statement if there is one running. Do not change the the flags.
@throws SQLException If there is an error closing the statement
jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java