问题
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
回答1:
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).
来源:https://stackoverflow.com/questions/43236799/how-to-insert-json-into-cassandra-using-api-querybuilder-and-batch