使用DataStax Java驱动程序1.0.4使用CQL连接到Cassandra时出现异常
我的笔记本电脑上运行着卡桑德拉1.2.11。我可以使用使用DataStax Java驱动程序1.0.4使用CQL连接到Cassandra时出现异常,java,cassandra,cql3,datastax-java-driver,Java,Cassandra,Cql3,Datastax Java Driver,我的笔记本电脑上运行着卡桑德拉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] Une
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文档。我尝试了几个端口号,包括退出with port()
调用,但似乎没有任何效果
Cluster cluster = new Cluster.Builder()
.addContactPoints("localhost")
.withPort(9160)
.build();
使用
telnet
我可以验证Cassandra服务器是否确实在侦听我指定的每个端口。我还验证了所有必需的库jar文件都在我的类路径上,如文档中所述。结果是我遗漏了文档中的一节
我使用的是一个旧的cassandra.yaml
配置文件,它来自早期版本的cassandra,没有启用本机传输二进制协议。以下代码段显示了我需要更改的设置:
# Whether to start the native transport server.
start_native_transport: true
# port for the CQL native transport to listen for clients on
native_transport_port: 9042
重新启动Cassandra后,客户端能够成功连接并运行CQL 3.0命令。请注意,创建连接的代码必须更改为使用文件中指定的端口,如下所示:
Cluster cluster = new Cluster.Builder()
.addContactPoints("localhost")
.withPort(9042)
.build();
另外,请注意,从和以上版本,本机传输在默认情况下处于启用状态。当您尝试将旧版本的java驱动程序与较新的cassandra版本一起使用时,也会出现此错误。我在Ubuntu中也遇到同样的问题。我最近安装了下面的命令,这是datastax指南 apt get install cassandra=2.0.11 dsc20=2.0.11-1 在那之前我只是 安装卡桑德拉 那对我来说也是一样。我刚刚用第一个命令(datastax指南)删除并安装了它 关于移除卡桑德拉,请使用下面的命令 卡桑德拉
我正在运行Cassandra Community 2.0.6,我需要使用哪个驱动程序版本?我试过2.0.1,但仍然会出错。我可以远程登录到端口和ip地址,这样我就知道它们正在运行。。。