How to connect to cassandra  using java

  • Cassandra is Nosql database.First cassandra is developed by Facebook for the inbox search future.
  • First you need to download DatastaxDriver jar for establishing the connection to cassandra database using java.
Sample Java program for establishing connection to cassandra

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public  class CassandraConnection  {

 public static void main(String[] args)  throws Exception{
   String serverIp ="";
   String keyspace = "mykeyspace";
   Cluster cluster = Cluster.builder()
   Session session = cluster.connect(keyspace);
   System.out.println("Connection Established");

In the above java program defining the server ip address.This Ip is getting where the cassandra is installed. Keyspace is nothing but database.By using keyspace we can create tables or columnfamilies in cassandra. 


Post a Comment