为何我无法连接到cassandra

我的笔记本电脑上有一个基本的cassandra设置,它可以使用命令行工具连接到它,但是在java中,以下操作失败:

Cluster cluster = new Cluster.Builder().addContactPoints("localhost").withPort(9160).build(); 

任何线索都会非常有用,谢谢! 错误是:

 com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1 ([localhost/127.0.0.1] Unexpected error during transport initialization (com.datastax.driver.core.TransportException: [localhost/127.0.0.1] Channel has been closed))) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:186) 

听起来你的cassandra服务器没有运行。 通过任务管理器或telnet 127.0.0.1 9160检查服务器是否正在运行

如果你得到以下cassandra没有运行:

 telnet: Unable to connect to remote host: Connection refused 

至于jdbc库,第一条建议,使用DataStax驱动程序(你可以只添加maven依赖 ),第二条建议……也可以使用maven for jdbc。 将依赖项添加到maven项目中,然后使用Wiki上的代码页 。

相关性:

  org.apache-extras.cassandra-jdbc cassandra-jdbc 1.2.5  

确保Cassandra正在运行! 🙂