Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Cassandra Java Driver
package com.example.cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Query;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
public class Cassandra {
private Session session = null;
public Cassandra(){
public Cassandra(String contactPoint){
Cluster cluster = new Cluster.Builder().
//I previously created a keyspace called "android"
this.session = cluster.connect("android");
public void saveOrUpdate(String cql) {
try {
catch(NoHostAvailableException nhae){
public ResultSet findByCQL(String cql){
try {
Query cqlQuery = new SimpleStatement(cql);
return session.execute(cqlQuery);
catch(NoHostAvailableException nhae){
return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.