Created
April 10, 2014 06:50
-
-
Save yangzhe1991/10349122 to your computer and use it in GitHub Desktop.
example code of QueryBuilder in Cassandra Java driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
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
thanks