我正在使用PreparedStatement和boundStatment来执行一些Cassandra查询 . 我正在尝试执行范围查询 . 这是我要创建的查询:
getAllRecordsOnIndexRange = getSession.prepare(QueryBuilder.select(documentId, documentName, documentIndex)
.from(tableName)
.where(QueryBuilder.eq(documentId,QueryBuilder.bindMarker()))
.and(QueryBuilder.gte(documentIndex, QueryBuilder.bindMarker()))
.and(QueryBuilder.lte(documentIndex, QueryBuilder.bindMarker())));
'documentId' 是分区键, 'documentIndex' 是群集键 . 我想对列documentIndex进行范围查询,如"get me all records with given documentId and documentIndex >= 3 and documentIndex <= 10"
当我想运行查询时,我打电话
public Statement buildGetAllRecordsOnIndexRange(int documentId, String documentName, int startDocumentIndex, int endDocumentIndex)
{
BoundStatement boundStatement = getAllRecordsOnIndexRange
.bind()
.setString(DOCUMENT_ID, documentId)
//how to set start and end documentIndex
databaseManager.applyReadStatementsConfiguration(boundStatement);
return boundStatement;
}
如何为上述查询设置startDocumentIndex和endDocumentIndex?
1 回答
我建议使用named bind markers而不是未命名 - 读取使用它们的代码要容易得多 . 因此,在您的情况下,代码将如下所示:
然后你可以绑定名字: