private static void queryByIterator()
      throws IoTDBConnectionException, StatementExecutionException {
    try (SessionDataSet dataSet = session.executeQueryStatement(SELECT_D1)) {

      DataIterator iterator = dataSet.iterator();
      System.out.println(dataSet.getColumnNames());
      dataSet.setFetchSize(1024); // default is 10000
      while (iterator.next()) {
        StringBuilder builder = new StringBuilder();
        // get time
        builder.append(iterator.getLong(1)).append(",");
        // get second column
        if (!iterator.isNull(2)) {
          builder.append(iterator.getLong(2)).append(",");
        } else {
          builder.append("null").append(",");
        }

        // get third column
        if (!iterator.isNull(ROOT_SG1_D1_S2)) {
          builder.append(iterator.getLong(ROOT_SG1_D1_S2)).append(",");
        } else {
          builder.append("null").append(",");
        }

        // get forth column
        if (!iterator.isNull(4)) {
          builder.append(iterator.getLong(4)).append(",");
        } else {
          builder.append("null").append(",");
        }

        // get fifth column
        if (!iterator.isNull(ROOT_SG1_D1_S4)) {
          builder.append(iterator.getObject(ROOT_SG1_D1_S4));
        } else {
          builder.append("null");
        }

        System.out.println(builder);
      }
    }
  }
This example shows how to insert data of TSDataType.TEXT. You can use the session interface to
write data of String type or Binary type.
example/session/src/main/java/org/apache/iotdb/SessionExample.java