I have Cassandra 1.2.11 running on my laptop. I can connect to it using nodetool
and cqlsh
but when I try and use the DataStax 1.0.4 Java API to connect using CQL 3.0 I get the following error:
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)
I am using the following code to connect, taken from the DataStax documentation. I have tried several port number, including leaving the withPort()
call out but nothing seems to work.
Cluster cluster = new Cluster.Builder()
.addContactPoints("localhost")
.withPort(9160)
.build();
Using telnet
I can verify that the Cassandra server is definitely listening at each of the ports I have specified. I have also verified that all the required library jar files are on my classpath as described in the documentation.