Using Apache Cassandra with Maven

Hi guys, from last few days i was working on a new technology called Apache Cassandra and here is my guidance to install and use it.
Apache Cassandra is an open source distributed database management system. It is an Apache Software Foundation top-level project, designed to handle very large amounts of data spread out across many commodity servers while providing a highly available service with no single point of failure. It is a NoSQL solution that was initially developed by Facebook
Cassandra provides a structured key-value store with tunable consistency.Keys map to multiple values, which are grouped into column families. The column families are fixed when a Cassandra database is created, but columns can be added to a family at any time. Furthermore, columns are added only to specified keys, so different keys can have different numbers of columns in any given family. The values from a column family for each key are stored together.

You can download the Apache Cassandra here and select one of the mirror link. After downloading extract the zip in one of the drives and create “\var\lib\cassandra\commitlog”,”\var\lib\cassandra\data”,”\var\lib\cassandra\saved_caches” folders in the root folder as these folders are used by cassandra server these folders are configures in conf/cassandra.yaml file.

once you are done with the creation navigate to bin dir and start cassandra.bat file. once it has started without error or exception then start cassandra-cli.bat(cassandra-client)

once the above steps are done correctly, Open Eclipse IDE with Maven capability(Assuming maven is already installed)
copy the below content in the POM.xml file

<project xmlns="" xmlns:xsi=""





Now to create a column family and insert data into it using java, follow the code as below.

package com.spark.cassandra.hector;

import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;

 * @author Mantha Pavan Kumar
public class CassandraHectorTest {

	private static StringSerializer stringSerializer = StringSerializer.get();

	 * @param args
	 * @throws Exception
	public static void main(String[] args) throws Exception {
		Cluster cluster = HFactory.getOrCreateCluster("TestCluster",

		Keyspace keyspaceOperator = HFactory.createKeyspace("DEMO",
		try {
			Mutator<String> mutator = HFactory.createMutator(keyspaceOperator,
			mutator.insert("jsmith", "users",
					HFactory.createStringColumn("first", "John"));

			ColumnQuery<String, String, String> columnQuery = HFactory
			QueryResult<HColumn<String, String>> result = columnQuery.execute();

			System.out.println("Read HColumn from cassandra: " + result.get());
					.println("Verify on CLI with: get DEMO.users['jsmith'] ");

		} catch (HectorException e) {


Happy Coding 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s