Why cant I connect to cassandra

13,560

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>
Share:
13,560
Jay
Author by

Jay

Experienced Java developer. Keen go (golang) developer.

Updated on June 04, 2022

Comments

  • Jay
    Jay almost 2 years

    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)