我的笔记本电脑上运行着 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 文件都在我的类路径中,如文档中所述。