mikestaszel mikestaszel - 1 month ago 10
Java Question

Datastax Java Cassandra Driver: Multiple AND statements using WHERE?

I'm trying to run the following CQL statement using the latest Datastax Cassandra driver for Java:

SELECT * FROM tablename WHERE column_one=1 AND column_2=9 AND column_3=50;


Here's what I have so far (only 2 ANDs), but I can't find a way to chain more than 2 where Clauses using and():

Statement select = QueryBuilder.select().all().from( "tablename").where(QueryBuilder.eq("column_one", 1)).and(QueryBuilder.eq("column_two", 9));


Thanks!

Answer

The following should work:

    Statement s = QueryBuilder.select().all()
        .from("tableName")
        .where(eq("column_1", 1))
        .and(eq("column_2", 9))
        .and(eq("column_3", 50));

It produces the following statement:

SELECT * FROM tableName WHERE column_1=1 AND column_2=9 AND column_3=50;