What you are trying to do is not currently supported:
https://issues.apache.org/jira/browse/CASSANDRA-4210.

That being said, you get that exact error because what you pass to bind()
is an array, but bind() is a variadic method, so this
is equivalent to writing:
  ResultSet results = execute(getUserInList.bind(“abc”, “def”, “ghi”));
which calls bind with 3 arguments, even though your prepared statement has
only one prepared variable.

So in theory you'd want to do
  ResultSet results = execute(getUserInList.bind(Arrays.asList(“abc”,
“def”, “ghi”)));
but then again, this won't work either because, as said above, this is not
yet supported Cassandra side.

Just for the sake of completness, what you can actually do is:

PreparedStatement getUserInList = prepare(QueryBuilder.select(ADDRESS,
USER).from(USER_BY_ADDRESS_COLUMN_FAMILY)
            .where(QueryBuilder.in(ADDRESS, QueryBuilder.bindMarker(),
QueryBuilder.bindMarker(), QueryBuilder.bindMarker())));

i.e., have 3 bind markers, and then the remaining of your initial code
would work (but I understand this is probably not what you
want, just being complete).

--
Sylvain


On Tue, Jul 9, 2013 at 5:21 PM, Pruner, Anne (Anne) <pru...@avaya.com>wrote:

>  Has anyone tried binding a prepared statement for an “IN” query?****
>
> ** **
>
> For example, ****
>
> ** **
>
> protected PreparedStatement getUserInList =
> prepare(QueryBuilder.select(ADDRESS,
> USER).from(USER_BY_ADDRESS_COLUMN_FAMILY)****
>
>             .where(QueryBuilder.in(ADDRESS, QueryBuilder.bindMarker())));*
> ***
>
> ** **
>
> Object[] addressList = {“abc”, “def”, “ghi”};****
>
> ResultSet results = execute(getUserInList.bind(addressList));****
>
> ** **
>
> ** **
>
> This results in a java.lang.IllegalArgumentException: Prepared statement
> has only 1 variables, 3 values provided****
>
> ** **
>
> Any ideas?****
>
> Thanks,****
>
> Anne Pruner****
>
> ** **
>
> ** **
>
> ** **
>

Reply via email to