Monday 8 June 2015

Insert Data Into Cassandra Example

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






Connect return cassandra connection

public class Connect {

    public static Session getConection(){
       
        Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build();

        Session session = cluster.connect("demo");

        return session;

    }
   
}

In test class we will insert data into cassandra database

import com.datastax.driver.core.Session;

public class Test {

    public static void main(String[] args) {

        Session session = Connect.getConection();
        String query = "insert into emp1(emp_id,ss_id,name) values(500,205,'raja')";
        session.execute(query);
        System.out.println("ok");
    }
}

No comments:

Post a Comment