Dashboard > iBATIS DataMapper > Home > Frequently Asked Questions > How do I use LIKE in my queries
How do I use LIKE in my queries
Added by Clinton Begin, last edited by Ted Husted on Sep 15, 2005  (view change)
Labels: 
(None)


Because iBATIS uses PreparedStatement for mapped statements, you have to use the $value$ syntax, or make your parameter contain your % or _ characters. For example, let's say you want your database will end up with is this:

select * from foo where value like 'x%'

You can do this:

select * from foo where value like #parm#

But if you do, it becomes this:

select * from foo where value like ?

To make that do what you want, you need to make the parameter "x%" by setting parm to "x%".

If you do not like that approach, you can do this instead:

select * from foo where value like '$parm$%'

That still uses a PreparedStatement, but the $parm$ gets inserted as a literal instead of a parameter. So, to get the same results as before, you would set parm to "x". Note that this can be vulnerable to SQL injection attacks, so make sure that all single quotes are escaped in parm.


Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators