private static void indent_DisplayNextRow(
      PrintWriter out,
      ResultSet rs,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {

    Vector nestedResults;

    // autocommit must be off or the nested cursors
    // are closed when the outer statement completes.
    if (!conn.getAutoCommit()) nestedResults = new Vector();
    else nestedResults = null;

    checkNotNull(rs, "ResultSet");

    ResultSetMetaData rsmd = rs.getMetaData();
    checkNotNull(rsmd, "ResultSetMetaData");

    // Only print stuff out if there is a row to be had.
    if (rs.next()) {
      int rowLen =
          indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths);
      DisplayRow(out, rs, rsmd, rowLen, nestedResults, conn, indentLevel, null, null);
    } else {
      indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow"));
    }

    ShowWarnings(out, rs);

    DisplayNestedResults(out, nestedResults, conn, indentLevel);
    nestedResults = null;
  } // DisplayNextRow
  public static void ShowWarnings(PrintStream out, Statement s) {
    try {
      // GET STATEMENT WARNINGS
      SQLWarning warning = null;

      if (s != null) {
        ShowWarnings(out, s.getWarnings());
      }

      if (s != null) {
        s.clearWarnings();
      }
    } catch (SQLException e) {
      ShowSQLException(out, e);
    }
  } // ShowStatementWarnings
  public static void ShowWarnings(PrintStream out, ResultSet rs) {
    try {
      // GET RESULTSET WARNINGS
      SQLWarning warning = null;

      if (rs != null) {
        ShowWarnings(out, rs.getWarnings());
      }

      if (rs != null) {
        rs.clearWarnings();
      }
    } catch (SQLException e) {
      ShowSQLException(out, e);
    }
  } // ShowResultSetWarnings
  public static void ShowWarnings(PrintStream out, Connection theConnection) {
    try {
      // GET CONNECTION WARNINGS
      SQLWarning warning = null;

      if (theConnection != null) {
        ShowWarnings(out, theConnection.getWarnings());
      }

      if (theConnection != null) {
        theConnection.clearWarnings();
      }
    } catch (SQLException e) {
      ShowSQLException(out, e);
    }
  } // ShowWarnings
  private static void indent_DisplayCurrentRow(
      PrintStream out,
      ResultSet rs,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {

    Vector nestedResults;

    if (rs == null) {
      indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow_19"));
      return;
    }

    // autocommit must be off or the nested cursors
    // are closed when the outer statement completes.
    if (!conn.getAutoCommit()) nestedResults = new Vector();
    else nestedResults = null;

    ResultSetMetaData rsmd = rs.getMetaData();
    checkNotNull(rsmd, "ResultSetMetaData");

    int rowLen = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths);
    DisplayRow(
        out,
        rs,
        rsmd,
        rowLen,
        nestedResults,
        conn,
        indentLevel,
        displayColumns,
        displayColumnWidths);

    ShowWarnings(out, rs);

    DisplayNestedResults(out, nestedResults, conn, indentLevel);
    nestedResults = null;
  } // DisplayNextRow
  private static void indent_DisplayResults(
      PrintStream out,
      Statement stmt,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {

    checkNotNull(stmt, "Statement");

    ResultSet rs = stmt.getResultSet();
    if (rs != null) {
      indent_DisplayResults(out, rs, conn, indentLevel, displayColumns, displayColumnWidths);
      rs.close(); // let the result set go away
    } else {
      DisplayUpdateCount(out, stmt.getUpdateCount(), indentLevel);
    }

    ShowWarnings(out, stmt);
  } // DisplayResults
  private static void indent_DisplayResults(
      PrintStream out,
      ResultSet rs,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {
    ResultSetMetaData rsmd = rs.getMetaData();
    checkNotNull(rsmd, "ResultSetMetaData");
    Vector nestedResults;
    int numberOfRowsSelected = 0;

    // autocommit must be off or the nested cursors
    // are closed when the outer statement completes.
    if (!conn.getAutoCommit()) nestedResults = new Vector();
    else nestedResults = null;

    if (displayColumnWidths == null)
      displayColumnWidths = getColumnDisplayWidths(rsmd, displayColumns, false);

    int len = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths);

    // When displaying rows, keep going past errors
    // unless/until the maximum # of errors is reached.
    boolean doNext = true;
    int retry = 0;
    while (doNext) {
      try {
        doNext = rs.next();
        if (doNext) {

          DisplayRow(
              out,
              rs,
              rsmd,
              len,
              nestedResults,
              conn,
              indentLevel,
              displayColumns,
              displayColumnWidths);
          ShowWarnings(out, rs);
          numberOfRowsSelected++;
        }
      } catch (SQLException e) {
        // REVISIT: might want to check the exception
        // and for some, not bother with the retry.
        if (++retry > MAX_RETRIES) throw e;
        else ShowSQLException(out, e);
      }
    }
    if (showSelectCount == true) {
      if (numberOfRowsSelected == 1) {
        out.println();
        indentedPrintLine(out, indentLevel, "1 row selected");
      } else if (numberOfRowsSelected >= 0) {
        out.println();
        indentedPrintLine(out, indentLevel, numberOfRowsSelected + " rows selected");
      }
    }

    DisplayNestedResults(out, nestedResults, conn, indentLevel);
    nestedResults = null;
  }
  private static void indent_DisplayResults(
      PrintWriter out,
      List resultSets,
      Connection conn,
      int indentLevel,
      int[] displayColumns,
      int[] displayColumnWidths)
      throws SQLException {

    ResultSetMetaData rsmd = null;

    // get metadata from the first ResultSet
    if (resultSets != null && resultSets.size() > 0)
      rsmd = ((ResultSet) resultSets.get(0)).getMetaData();

    checkNotNull(rsmd, "ResultSetMetaData");
    Vector nestedResults;
    int numberOfRowsSelected = 0;

    // autocommit must be off or the nested cursors
    // are closed when the outer statement completes.
    if (!conn.getAutoCommit()) nestedResults = new Vector();
    else nestedResults = null;

    if (displayColumnWidths == null)
      displayColumnWidths = getColumnDisplayWidths(rsmd, displayColumns, true);

    int len = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths);

    // When displaying rows, keep going past errors
    // unless/until the maximum # of errors is reached.
    int retry = 0;

    ResultSet rs = null;
    boolean doNext = true;
    for (int i = 0; i < resultSets.size(); i++) {
      rs = (ResultSet) resultSets.get(i);
      doNext = true;
      while (doNext) {
        try {
          doNext = rs.next();
          if (doNext) {

            DisplayRow(
                out,
                rs,
                rsmd,
                len,
                nestedResults,
                conn,
                indentLevel,
                displayColumns,
                displayColumnWidths);
            ShowWarnings(out, rs);
            numberOfRowsSelected++;
          }
        } catch (SQLException e) {
          // REVISIT: might want to check the exception
          // and for some, not bother with the retry.
          if (++retry > MAX_RETRIES) throw e;
          else ShowSQLException(out, e);
        }
      }
    }
    if (showSelectCount == true) {
      if (numberOfRowsSelected == 1) {
        out.println();
        indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_1RowSelec"));
      } else if (numberOfRowsSelected >= 0) {
        out.println();
        indentedPrintLine(
            out,
            indentLevel,
            LocalizedResource.getMessage(
                "UT_0RowsSelec", LocalizedResource.getNumber(numberOfRowsSelected)));
      }
    }

    DisplayNestedResults(out, nestedResults, conn, indentLevel);
    nestedResults = null;
  }