use datastax java driver to bind data for where in clause

流过昼夜 提交于 2019-12-12 02:55:22

问题


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)

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

select * from cf where key in (?)

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

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

Now I have a boundStatement.

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

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

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

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

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'')

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

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

Can any help me? Thanks!


回答1:


The correct syntax is:

SELECT * FROM cf WHERE key IN ?

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



来源:https://stackoverflow.com/questions/27432139/use-datastax-java-driver-to-bind-data-for-where-in-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!