Skip to content

@shehaaz /CassandraDriver.java
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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(){
this("127.0.0.1");
}
public Cassandra(String contactPoint){
Cluster cluster = new Cluster.Builder().
addContactPoints(contactPoint).build();
//I previously created a keyspace called "android"
this.session = cluster.connect("android");
}
public void saveOrUpdate(String cql) {
try {
session.execute(cql);
}
catch(NoHostAvailableException nhae){
}
}
public ResultSet findByCQL(String cql){
try {
Query cqlQuery = new SimpleStatement(cql);
cqlQuery.setConsistencyLevel(ConsistencyLevel.QUORUM);
cqlQuery.enableTracing();
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.