Java 为什么我无法连接到 cassandra

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18146781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:45:21  来源:igfitidea点击:

Why cant I connect to cassandra

javacassandra

提问by Jacob

I have a basic cassandra setup on my laptop, its up and I can connect to it using the command line tools, however in java, the following fails:

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

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

Any clues would be really helpful, thanks! The error is:

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

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)

采纳答案by Lyuben Todorov

Sounds like your cassandra server isn't running. Check that the server is running via the task manager or telnet 127.0.0.1 9160

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

If you get the below cassandra isn't running:

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

telnet: Unable to connect to remote host: Connection refused

As for the jdbc library, 1st piece of advice, use the DataStax driver (you can just add a maven dependency), second piece of advice... use maven for jdbc too. Add the dependency into a maven project and then used the code page on the wiki.

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

Dependency:

依赖:

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

回答by Chiron

Make sure that Cassandra is running! :)

确保 Cassandra 正在运行!:)