I was a bit stumped by this one not long ago so here is an example of correctly binding a value to a LIKE
clause inside a SQL
statement with Java
First, however, lets see the incorrect way that does not work...If you define your SQL
statement to have the bind value and a LIKE
wildcard, the JDBC
engine will not be able to process it.
The above code throws this kind of exception...
The correct way to do it is to treat the bind variable for the LIKE
statement just as you would any other bind variable. The code then looks like this...
Note that the SQL
string itself does not have the LIKE
wildcard. The wildcard is defined when you bind the variable using the setString()
Hope you found this post useful...
...so please read on! I love writing articles that provide beneficial information,
tips and examples to my readers. All information on my blog is provided free of
charge and I encourage you to share it as you wish. There is a small favour I ask in return however -
engage in comments below, provide feedback, and if you see mistakes let me know.
If you want to show additional support and help me pay for web hosting and
domain name registration,
donations, no matter how small, are always welcome!
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...