Reputation: 137
I see that all examples for JSON uses the query as string like
String cqlStatement = "INSERT INTO users JSON '{\"id\":888 , \"age\":21 ,\"state\":\"TX\"}'";
but I want to use QueryBuilder, since I would like to insert in batch.
Thanks
Upvotes: 0
Views: 601
Reputation: 12840
Use Insert.json() method
Inserts the provided object, using the INSERT INTO ... JSON syntax introduced in Cassandra 2.2.
Example :
QueryBuilder.insertInto("my_data").json("{\"id\": 1, \"value\": \"This is a test\"}");
Note : Any columns which are omitted from the JSON string will be defaulted to a NULL value (which will result in a tombstone being created).
Upvotes: 1