1

during execution query i received error Expected positional parameter count: 1, actual parameters: [] my query not have any parameters, BUT query contains ? as value.

code

session.createSQLQuery(sql).list()

sql

SELECT file.name as `NAME` FROM film WHERE film.name IN ('You say "How I can make it? We' ..."');

EDIT

it also reproduced if search by name that contains ? and '

SELECT file.name as `NAME` FROM film WHERE film.name IN ('?'')

How I can fix it?

Thanks.

1
  • @Unknown root cause in ' with ? Commented Oct 12, 2016 at 11:53

1 Answer 1

2

Should work

String[] values= {"You say \"How I can make it? We' ...\""};
String sql = "SELECT file.name as `NAME` FROM film WHERE film.name IN (:values)";
SQLQuery query = session.createSQLQuery(sql);
query.setParameterList("values", values);

and then

query.list();
Sign up to request clarification or add additional context in comments.

3 Comments

query generated dynamic, i can't handle value into IN
Then your code has SQL injection. Suppose I pass the name variable as '); DROP table users; Will your query drop the table?
no, because it value was into IN and occurred sql exception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.