【问题标题】:Passing variable value to cassandra cql statement [duplicate]将变量值传递给cassandra cql语句[重复]
【发布时间】:2013-07-15 13:29:30
【问题描述】:

我有 Java 代码来访问和处理 Cassandra 中的数据。如何将 Java 变量传递给用 Java 编写的 Cassandra CQL 查询。代码如下:

我的代码是这样的:

itemname="Item01";

com.datastax.driver.core.PreparedStatement result = 
session.execute("select itemname from demodb.retail_transaction where itemnamw = itemname;");

但它给出了以下错误:

no viable alternative at input ';'

【问题讨论】:

  • 你问的问题基本上和以前一样。
  • 我猜你准备的语句写错了。

标签: java cassandra


【解决方案1】:

我认为您应该像这样将变量绑定到准备好的语句:

    itemname="Item01";
    itemtype="type01";
    com.datastax.driver.core.PreparedStatement result = 
    session.execute("select itemname from demodb.retail_transaction where itemnamw = ? and 
                    itemtype =?;");
    BoundStatement boundStatement = new BoundStatement(statement);
    ResultSet results = session.execute(boundStatement.bind(
              itemname,itemtype));

【讨论】:

    猜你喜欢
    • 2021-09-28
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 2014-08-22
    相关资源
    最近更新 更多