为什么不能连接到cassandra [英] Why cant I connect to cassandra

查看:1443
本文介绍了为什么不能连接到cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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)


推荐答案

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

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未运行:

If you get the below cassandra isn't running:

telnet: Unable to connect to remote host: Connection refused

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

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.

依赖关系:

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

这篇关于为什么不能连接到cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆