使用datastax Java驱动程序为where in子句绑定数据 [英] use datastax java driver to bind data for where in clause

查看:85
本文介绍了使用datastax Java驱动程序为where in子句绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有人问过这个问题( http://www.datastax.com/support-forums/topic/java-driver-cql-3-bound-statements-in-clause#post-13114 ,< a href = https://stackoverflow.com/questions/16918853/prepared-statement-with-collection-in-in-clause-in-datastax-cassandra-cql-driver>在Datastax的IN子句中带有集合的预声明Cassandra CQL驱动程序)

I know somebody has ask this question (http://www.datastax.com/support-forums/topic/java-driver-cql-3-bound-statements-in-clause#post-13114, Prepared Statement with collection in IN clause in Datastax Cassandra CQL driver)

但是,我仍然不知道如何绑定数据。以
为例,我的prepareStatement是

However, I still do not know how to bind data. for example, my preparedStatement is

select * from cf where key in (?)

我想要的是绑定数据,而cql看起来像是

What I want is bind data and the cql is looks like

select * from cf where key in ('key1', 'key2')

现在我有一个boundStatement。

Now I have a boundStatement.

当我使用boundStatment.bind()api时。我尝试绑定?

when I use boundStatment.bind() api. I try to bind ? with a List or a Array, however , it says:


列值是varchar类型,不能设置为列表

Column value is of type varchar, cannot set to a list

好,我设置一个字符串并使用boundStatement.bind像这样:

Ok, I set a string and use boundStatement.bind like this:

boundStatement.bind("'key1','key2'");

没有例外,但是resultSet为空。为什么?我认为是因为驱动程序将其解析为

There is no exception, but the resultSet is empty. Why? I think because the driver parse it as

select * from cf where key in (''key1', 'key2'')

(请注意,因为它认为所有的 key1和 key2都是

(notice a redundant quote because it thinks all the "'key1',and 'key2'" is a string).

所以,我知道datastax在子句中有支持。但是我找不到一些例子..

So, I know datastax has support in clause. but I can not find some examples ..

有什么可以帮到我吗?
谢谢!

Can any help me? Thanks!

推荐答案

正确的语法是:

SELECT * FROM cf WHERE key IN ?

这将允许您为查询参数绑定列表。

That will allow you to bind a List for the query parameter.

这篇关于使用datastax Java驱动程序为where in子句绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆