go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Establish Connection
 
Subject: Establish Connection
Author: EricJ
In response to: Apache Cassandra -- Access via Java
Posted on: 11/13/2016 10:27:04 PM


	Cluster cluster = Cluster.builder().
				addContactPoint("10.11.12.13").
				build();
	
	Session session = cluster.connect();
	
	Metadata metadata = cluster.getMetadata();
	
	System.out.printf("Connected to cluster: %s\n",	metadata.getClusterName());
	
	for (Host host : metadata.getAllHosts()) {

   	    System.out.printf("Datatacenter: %s; Host: %s; Rack: %s --> Is up? : %s\n",
			host.getDatacenter(), host.getAddress(), host.getRack(), host.isUp());
	}



OUTPUT:
Connected to cluster: Test Cluster
Datatacenter: datacenter1; Host: /10.11.12.13; Rack: rack1 --> Is up? : true
Datatacenter: datacenter1; Host: /10.11.12.123; Rack: rack1 --> Is up? : false


Note: The second instance of this cluster is not running.



 

> On 11/13/2016 10:19:03 PM EricJ wrote:

There are several Java driver provider. One of them is from DataStax.com: cassandra-driver-core "3.0.0" (cassandra-driver-core-3.0.0.jar), which can be downloaded from:

https://www.versioneye.com/java/com.datastax.cassandra:cassandra-driver-core/3.0.0







References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.