Getting metadata

Let's dive into some action by writing our first program, which will create a Cluster object and fetch some metadata from the cluster. Let's name the program GetMetadata.java:

import com.datastax.driver.core.*;public class GetMetadata {  public static void main(String[] args) {    Cluster cluster =         Cluster.builder().addContactPoints("127.0.0.1").build();    Metadata metadata = cluster.getMetadata();    System.out.printf("Cluster name: %sn", metadata.getClusterName());    for (Host host : metadata.getAllHosts()) {      System.out.println("Host: " + host.getAddress() + "n");    }    cluster.close();  }}

Program 1: GetMetadata.java

Upon executing the previous program, you should see the result like this:

You might get a different cluster name based ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.