如果复制不起作用,如何将数据从csv文件导入cassandra…复制错误

zlhcx6iw  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(287)

我试图从csv文件导入数据,但出现以下错误:-原因:com.datasax.driver.core.exceptions.syntaxerror:line1:0输入“copy”([copy]…)处的可行替代方案
我的代码是:

  1. import com.datastax.driver.core.*;
  2. //import java.io.BufferedReader;
  3. //import java.io.FileReader;
  4. //import java.io.IOException;
  5. //import org.apache.commons.lang.StringUtils;
  6. public class Test {
  7. private static Session getSession(String[] contactPoints) {
  8. Cluster cluster = Cluster.builder()
  9. // Initial set of nodes to connect to. All nodes do not need to be
  10. // specified. The cassandra driver will self discover other nodes
  11. // in the cluster, so you just need to specify an initial handful.
  12. .addContactPoints(contactPoints)
  13. .withCredentials("testclust0011_rw", "SqecXzR8")
  14. .withSSL() // remove if SSL is not enabled
  15. .build();
  16. return cluster.connect("testclust0011");
  17. // You're connected! Do work here...
  18. }
  19. public static void main(String[] args) {
  20. //String serverIp = "169.125.178.237";
  21. //String keyspace = "testclust0011";
  22. String [] contactPoints = new String []{"169.125.178.237","169.99.199.36","169.125.176.196","169.99.198.228","169.91.232.142","169.99.199.19"};
  23. Session session = getSession(contactPoints);
  24. // String cqlStatement = "SELECT * FROM emp";
  25. // String cql = "CREATE TABLE testclust0011.PrAudit(eventTypeId int PRIMARY
  26. KEY,prinId int,requestorId int,eventSpec text)";
  27. // session.execute(cql);
  28. // String cql = "INSERT INTO PrAudit(eventTypeId,prinId,requestorId,eventSpec)
  29. VALUES(1,2,3,'password')";
  30. // session.execute(cql);
  31. for (Row row : session.execute(cqlStatement)) {
  32. System.out.println(row.toString());
  33. }
  34. String ss = "COPY PrAudit " +
  35. "from 'c://Users//V786612//sales.csv' ";
  36. session.execute(ss);
  37. session.close();
  38. }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题