全部产品
MaxCompute

BufferedWriter上传示例

更新时间:2017-06-07 13:26:11   分享:   

代码片段:

  1. // 初始化 MaxCompute 和 tunnel 的代码
  2. RecordWriter writer = null;
  3. TableTunnel.UploadSession uploadSession = tunnel.createUploadSession(projectName, tableName);
  4. try {
  5. int i = 0;
  6. // 生成TunnelBufferedWriter的实例
  7. writer = uploadSession.openBufferedWriter();
  8. Record product = uploadSession.newRecord();
  9. for (String item : items) {
  10. product.setString("name", item);
  11. product.setBigint("id", i);
  12. // 调用write接口写入数据
  13. writer.write(product);
  14. i += 1;
  15. }
  16. } finally {
  17. if (writer != null) {
  18. // 关闭TunnelBufferedWriter
  19. writer.close();
  20. }
  21. }
  22. // uploadSession提交,结束上传
  23. uploadSession.commit();
本文导读目录
本文导读目录
以上内容是否对您有帮助?