code: public void exportFromResultSet(Connection connection, ResultSet res, File fileName, ProgressVisitor progress, String encoding) throws SQLException {
          Csv csv = new Csv();
          String csvOptions = "charset=UTF-8 fieldSeparator=\t fieldDelimiter=\t";
          if (encoding != null) {
              csvOptions = String.format("charset=%s fieldSeparator=\t fieldDelimiter=\t", encoding);
          }
          csv.setOptions(csvOptions);
          csv.write(fileName.getPath(), res, null);
      }
docs: Export a resultset to a TSV file
  
  @param connection
  @param res
  @param fileName
  @param progress
  @param encoding
  @throws java.sql.SQLException