code: @Override
      public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException {
          String regex = ".*(?i)\\b(select|from)\\b.*";
          Pattern pattern = Pattern.compile(regex);
          Matcher matcher = pattern.matcher(tableReference);
          if (matcher.find()) {
              if (tableReference.startsWith("(") && tableReference.endsWith(")")) {
                  if (FileUtil.isExtensionWellFormated(fileName, "tsv")) {
                      try (Statement st = connection.createStatement()) {
                          JDBCUtilities.attachCancelResultSet(st, progress);
                          exportFromResultSet(connection, st.executeQuery(tableReference), fileName, new EmptyProgressVisitor(), encoding);
                      }
                  } else {
                      throw new SQLException("Only .tsv extension is supported");
                  }
  
              } else {
                  throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'.");
              }
          } else {
              if (FileUtil.isExtensionWellFormated(fileName, "tsv")) {
                  final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData());
                  TableLocation location = TableLocation.parse(tableReference, isH2);
                  try (Statement st = connection.createStatement()) {
                      JDBCUtilities.attachCancelResultSet(st, progress);
                      exportFromResultSet(connection, st.executeQuery("SELECT * FROM " + location.toString()), fileName,new EmptyProgressVisitor(),encoding);
                  }
              } else {
                  throw new SQLException("Only .tsv extension is supported");
              }
          }        
      }
docs: Export a table or a query to as TSV file
  
  @param connection Active connection, do not close this connection.
  @param tableReference [[catalog.]schema.]table reference
  @param fileName File path to read
  @param progress
  @param encoding
  @throws SQLException
  @throws IOException