Collection view in java and CQL

I am new to cassandra and I am trying to add a dataset to a table. My table looks like this:

CREATE TABLE myTable (id int, name varchar, mySet set<uuid>, PRIMARY KEY (id));

The problem that I encountered when I execute my query is that the type is incompatible, the string representation of the set in Java is [uuid1, uuid2, ...], and the representation in cql is {'uuid1', 'uuid2', ... }

session.execute("INSERT INTO myTable (id , name, mySet) VALUES (" + myID + ", '" + myName +"' ," + mySet + ");");

Do you guys know if there is a function or library that will directly fix this problem. Many thanks.

+4
source share
2 answers

Instead of adding the contents of the set to the query string (which uses the implementation of set.toString ()), you could do the following (cassandra 2.0 + is required):

session.execute("INSERT INTO myTable (id, name, mySet) VALUES (?, ?, ?));", myId, myName, mySet);

, . BoundStatement QueryBuilder .

+5

. , C * , , p_stmnt, . p_stmnts c * , , .

+3

Source: https://habr.com/ru/post/1584135/


All Articles