我在我的笔记本电脑上运行着Cassandra 1.2.11。我可以使用nodetool
和cqlsh
连接它,但是当我尝试使用DataStax 1.0.4 Java API使用CQL 3.0连接时,我遇到了以下错误:
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)
我正在使用以下代码进行连接, 该代码来自于DataStax文档。我尝试了几个端口号,包括在代码中删除 withPort()
, 但似乎没有起作用。
Cluster cluster = new Cluster.Builder()
.addContactPoints("localhost")
.withPort(9160)
.build();
使用telnet
,我可以验证Cassandra服务器正在监听我指定的每个端口。我还验证了所有必需的库jar文件已按照文档说明添加到我的类路径中。