Skip to content

Instantly share code, notes, and snippets.

@bsbodden
Created December 3, 2014 04:27
Show Gist options
  • Save bsbodden/27309f7b698deb898e3e to your computer and use it in GitHub Desktop.
Save bsbodden/27309f7b698deb898e3e to your computer and use it in GitHub Desktop.
HelloCassandra.java: Main Method
public static void main(String[] args) {
Cluster cluster = null;
Session session = null;
try {
cluster = Cluster.builder().addContactPoints("localhost").build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
for ( Host host : metadata.getAllHosts() ) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack());
}
} catch (NoHostAvailableException nhae) {
System.err.println("No alive hosts to use:" + nhae.getMessage());
System.exit(1);
} catch (Exception e) {
System.err.println("Unexpected error: " + e.getMessage());
e.printStackTrace();
System.exit(1);
} finally {
//session.close();
cluster.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment