为什么我不能连接到cassandra

Jac*_*cob 4 java cassandra

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

Cluster cluster = new Cluster.Builder().addContactPoints("localhost").withPort(9160).build();
Run Code Online (Sandbox Code Playgroud)

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

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)
Run Code Online (Sandbox Code Playgroud)

Lyu*_*rov 6

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

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

telnet: Unable to connect to remote host: Connection refused
Run Code Online (Sandbox Code Playgroud)

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

相关性:

<dependency>
    <groupId>org.apache-extras.cassandra-jdbc</groupId>
    <artifactId>cassandra-jdbc</artifactId>
    <version>1.2.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)