4

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)
Jay
  • 19,649
  • 38
  • 121
  • 184
  • Im having no problems using the cassandra jdbc library either. – Jay Aug 09 '13 at 12:38
  • 1
    I know I might sound stupid, but is Cassandra running? – Chiron Aug 09 '13 at 12:45
  • 1
    @Chiron It doesn't, that is exactly the problem. @Jacob verify that cassandra is running by using `telnet 127.0.0.1 9160` – Lyuben Todorov Aug 09 '13 at 13:16
  • 1
    check the logfiles of cassandra for errors and warnings – mschenk74 Aug 09 '13 at 13:24
  • 1
    check if the interface settings in the configuration of cassandra are correct: if you want cassandra to listen on more than one ip-adress (which is the case if you want to use localhost AND the ip-adress specified for the network connection) then you have to use 0.0.0.0 as Ip-Adress in the config. – mschenk74 Aug 09 '13 at 13:27
  • It IS running, I mentioned I can connect to it from the command line. And I did try telnet that way. – Jay Aug 10 '13 at 08:12

2 Answers2

6

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

If you get the below cassandra isn't running:

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.

Dependency:

<dependency>
    <groupId>org.apache-extras.cassandra-jdbc</groupId>
    <artifactId>cassandra-jdbc</artifactId>
    <version>1.2.5</version>
</dependency>
Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • Thanks. I did already try that. – Jay Aug 10 '13 at 08:13
  • 1
    Turns out restarting Cassandra fixed it, don't know why, but it did. – Jay Aug 12 '13 at 10:06
  • Do you have any recommendations, what to check if cassandra is running? I am using ssh tunnel and telnet is working for both ports 9160 and 9042, but still I cannot connect, not by java app nor datastax devcenter with the same error(NoHostAvailable). – LadyWoodi Aug 13 '14 at 11:24
  • 1
    @LadyWoodi ssh into the server and try running cqlsh (its in the bin/ directory) If it connects C* is running, if not, open up cassandra.yaml (in the conf/ directory) and check your listen_address then try (again from the local server) ./cqlsh listen_address (e.g.: ./cqlsh 192.168.1.100) – Lyuben Todorov Aug 13 '14 at 11:29
0

Make sure that Cassandra is running! :)

Chiron
  • 20,081
  • 17
  • 81
  • 133