1
votes

My code in Java:

public static void main(String[] args) {
    Cluster cluster;
    Session session;

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

    session = cluster.connect("Bundesliga");

    session.execute("INSERT INTO test(c1,c2,c3,c4,c5) VALUES(0,0,0,0,0)");
}

Error Message:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (null)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:80) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1145) at com.datastax.driver.core.Cluster.init(Cluster.java:149) at com.datastax.driver.core.Cluster.connect(Cluster.java:225) at com.datastax.driver.core.Cluster.connect(Cluster.java:258) at cassandra.cassandra_main.main(cassandra_main.java:19)

I have already looked in cassandra.yaml:

start_native_transport: true

native_transport_port: 9042

1
Are you sure that cassandra is listening on localhost? Since the nodes in a cassandra cluster must talk to each other they usually open their port on the external IP address.Thomas Stets
in cassandra.yaml is the listen_adress on localhostfsstudent
can you include output of netstat -anp | grep 9042 ?Chris Lohfink
tcp 0 0 0.0.0.0:9042 0.0.0.0:0* LISTEN 3738/javafsstudent

1 Answers

1
votes

I fixed it.

The problem were, that the version of the cassandra-driver-core was not compatible with the cassandra version.