Skip to content

Instantly share code, notes, and snippets.

@yangzhe1991
Created April 10, 2014 06:50
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yangzhe1991/10349122 to your computer and use it in GitHub Desktop.
Save yangzhe1991/10349122 to your computer and use it in GitHub Desktop.
example code of QueryBuilder in Cassandra Java driver
Session session = getSession();
//update
Statement exampleQuery = QueryBuilder.update("keyspace","table").with(QueryBuilder.set("height", 180))
.and(QueryBuilder.set("width", 300)).where(QueryBuilder.eq("id", 5145924587302797538L));
session.execute(exampleQuery);
//insert
exampleQuery= QueryBuilder.insertInto("keyspace","table").value("id",12245L)
.value("data",ByteBuffer.wrap(new byte[]{0x11})).ifNotExists();
session.execute(exampleQuery);
//select
exampleQuery= QueryBuilder.select().from("keyspace","table").where(QueryBuilder.gt("height",450))
.and(QueryBuilder.eq("product","test")).limit(50).orderBy(QueryBuilder.asc("id"));
ResultSet results= session.execute(exampleQuery);
for(Row r:results.all()){
System.out.println(r.toString());
}
@AaronFaltesek
Copy link

thanks

@Sanskar49
Copy link

What if I wanted to insert a map say a map of type map<String,Object> into the table?? What can I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment