Problems with string parameter insertion into prepared statement
Posted
by c0d3x
on Stack Overflow
See other posts from Stack Overflow
or by c0d3x
Published on 2010-02-19T12:04:20Z
Indexed on
2010/06/02
16:04 UTC
Read the original article
Hit count: 261
Hi,
I have a database running on an MS SQL Server. My application communicates via JDBC and ODBC with it. Now I try to use prepared statements.
When I insert a numeric (Long) parameter everything works fine. When I insert a string parameter it does not work. There is no error message, but an empty result set.
WHERE column LIKE ('%' + ? + '%') --inserted "test" -> empty result set
WHERE column LIKE ? --inserted "%test%" -> empty result set
WHERE column = ? --inserted "test" -> works
But I need the LIKE functionality. When I insert the same string directly into the query string (not as a prepared statement parameter) it runs fine.
WHERE column LIKE '%test%'
It looks a little bit like double quoting for me, but I never used quotes inside a string. I use preparedStatement.setString(int index, String x) for insertion.
What is causing this problem? How can I fix it?
Thanks in advance.
© Stack Overflow or respective owner