Ajay Takur
Ajay Takur

Reputation: 6236

Cassandra is throwing NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1 (null))

I am not able to connect to Cassandra cluster using this code:

public static boolean tableCreate() {
        // Query
        String query = "CREATE KEYSPACE store WITH replication "
                + "= {'class':'SimpleStrategy', 'replication_factor':1};";

        // creating Cluster object
        Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").withPort(9042).build();

        // Creating Session object
        Session session = cluster.connect("tutorialspoint");

        // Executing the query
        session.execute(query);

        // using the KeySpaceq
        session.execute("USE store");
        System.out.println("Keyspace created with store name");

        return true;
    }

It is giving me this error:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1 (null))

What is my mistake in the code above?

Cassandra is running on my Local Windows 10 64bit and I also disabled the firewall.

Upvotes: 2

Views: 12308

Answers (1)

Anurag
Anurag

Reputation: 916

You may need to check and possibly update the version of datastax driver that you are using. I faced exactly same error (ie same error message while connecting) and after upgrading driver 'datastax' version the problem went away and I could connect to DB.

Similar Issue: Unable to connect to Cassandra cluster running on local host

Upvotes: 3

Related Questions