Search code examples
javacassandralocalcqlsh

Cassandra: How to query local Table from local node in Java?


I have a three-node cluster with replicationfactor 2 and I want to receive the table local from keyspace 'system'. That means I want to acess local data of a Cassandra node. Is that possible?


Solution

  • Yes. You can query the system.local table from within Java just like any other.

        session = cluster.connect();
        ResultSet results = getSession()
            .execute("SELECT key,broadcast_address,cql_version FROM system.local");
    
        for (Row row : results) {
            System.out.println(row.getString("key") + " "
                + row.getInet("broadcast_address") + " "
                + row.getString("cql_version"));
        }
    
    local 127.0.0.1 3.4.4