ibatis sqlMap, LIKE operator

  • Thread starter this is not my name
  • Start date
T

this is not my name

I've been using iBatis sql maps in my J2EE application with great
results so far, but I've come across a bit of a roadblock, and my usual
savior, Google, hasn't been able to help me out of this one. The one
hits that seems to be exactly what I am looking for seems to have
vanished from the web:


http://www.mail-archive.com/[email protected]/msg00284.html


I can't seem to get queries that use the LIKE operator to work.
According to the sqlmap docs, this should work:

SELECT * FROM PRODUCT WHERE PRD_DESCRIPTION LIKE '%dog%'
OR
SELECT * FROM PRODUCT WHERE PRD_DESCRIPTION LIKE #value#
// description property == "%dog%"

When I run the SQL against my MySql db, I get results. When I run the
SQL using sqlMaps (substituting my String and the % operators for
#value#), I get no results. Here is my SQL (with table/column names
replaced):

select count(*) myCount from table_t
where field_f like '%45111q%'

in my sqlmap XML file, I have this SQL:

select count(*) myCount from table_t
where field_f like #value#

// (I know string appends waste mem)
I am passing in a String like this: String s = "%" + someStr + "%"

I have tried specifiying the parameterClass as java.lang.String as well
as not specifying at all.

I suspect the % sign is being escaped somehow, but cannot determine
this. Both my logging and MySQLs loggnig just show ? in the statement.
SqlMap logging shows this:


PreparedStatementLogProxy - {pstm-100121} Parameters:
[%h80111n6gb111c31o8zezojqdh111111%]



Has anyone managed to use LIKE successfully? It would be a huge help to
overcome this problem.


Thanks,
-BR
 
Joined
Sep 23, 2006
Messages
1
Reaction score
0
SqlMap like statement

You need to use a different operator for the value to add the percent signs to the statement:

SELECT * FROM PRODUCT WHERE PRD_DESCRIPTION LIKE '%$value$%'

you can obviously drop the % signs from the string that's being passed into the $value$ parameter!

HTH
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top