在我的示例应用中,以下代码段工作正常。
SELECT_CQL = "SELECT * FROM " + STREAM_NAME_IN_CASSANDRA + " WHERE '" + CONTEXT_ID_COLUMN + "'=?";
Connection connection = getConnection();
statement = connection.prepareStatement(SELECT_CQL);
statement.setString(1, "123");
resultSet = statement.executeQuery();
但是当我尝试在where子句中添加另一个参数时,查询不返回任何内容!
SELECT_CQL = "SELECT * FROM " + STREAM_NAME_IN_CASSANDRA + " WHERE '" + CONTEXT_ID_COLUMN + "'=? AND '"+TIMESTAMP_COLUMN+"'=?";
Connection connection = getConnection();
statement = connection.prepareStatement(SELECT_CQL);
statement.setString(1, "123");
statement.setString(2, "1390996577514");
resultSet = statement.executeQuery();
当我在cqlsh终端中尝试完全查询时,它可以正常工作。
答案 0 :(得分:1)
statement.setString(2, "1390996577514");
仔细检查TIMESTAMP_COLUMN
的数据类型,确保它是一个字符串。否则,您将需要使用适当的“设置”方法。例如:
statement.setLong(2, 1390996577514L);