java - 为什么我不能连接到 Cassandra

标签 java 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 dependency ),第二个建议...对 jdbc 也使用 maven。将依赖添加到 maven 项目中,然后使用 the code page on the wiki .

依赖:

<dependency>
    <groupId>org.apache-extras.cassandra-jdbc</groupId>
    <artifactId>cassandra-jdbc</artifactId>
    <version>1.2.5</version>
</dependency>

关于java - 为什么我不能连接到 Cassandra ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18146781/

相关文章:

java - 如何检查日期范围是否是完整的日历月?

java - 返回上一个 Activity

cassandra - 是否可以在不指定第一个的情况下按第二个簇键进行过滤?

java - 如何在 Servlet 上创建 REST API 以使用访问 token 进行身份验证

java - 如何使用 REST Api,然后将热门故事显示为 JSON

java - REST服务和定时消息发送

database-design - 在 Cassandra 中拥有许多键空间和可能的数千个表是个好主意吗?

cassandra - Cassandra 中的更新不是反模式吗?

cassandra - OpsCenter for Cassandra 是否会降低 Cassandra 的速度?

java - 如何压缩uuid和timeuuid?