...

How to disable the wildcards(% and _)

kasipandian
02-03-2008, 01:22 PM
Hi Friends,
I have a search option in my web page. My input from UI is any thing like alphabets,numbers, special chars(%$#_). My query is select * from vendor where vendor_name like 'vendorname%'; The condition input is(vendorname) anything. Based on the input i have to display the results. My query is working fine for all conditions except the input % and _. B'coz, these values are wild cards in Database. How can I send as a String in database if the values are %_. I'm using Java, J2ee and DB2. Please help me.
Regards
Kasi.

ralph l mayo
02-05-2008, 05:16 PM
I don't know for certain whether this applies to regular syntax (as opposed to advanced syntax) but it looks like you probably want to follow this general form:

Wildcards ("%", "_") (http://publib.boulder.ibm.com/infocenter/cmgmt/v8r3m0/index.jsp?topic=/com.ibm.apg.doc/cmbapmst164.htm)
Just as the LIKE operator, advanced syntax uses "%" and "_" as wildcards. The percent sign "%" is a wildcard character used to represent any number of arbitrary characters. The underscore "_" is a wildcard character used to represent a single arbitrary character. If you want a wildcard character to be treated as a regular character, you need to do the following:

1. Precede the wildcard character with an escape character
2. Add an ESCAPE clause after EACH term where you use the escape character

Example A:

/Book[contains-text-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' ")=1] SORTBY (score-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' "))

In this example, an exclamation mark "!" is used as an escape character before the underscore.

Example B:

/Book[contains-text-db2 (@Title, " 'Usage of underscore !_ in query' ESCAPE '!' | 'Yahoo! For Dummies' | 'Usage of underscore !_ on Yahoo!!' ESCAPE '!' | 'War and Peace' ")=1]

Note that an ESCAPE clause must be added after every term in your text search string where you escape wildcards, even if the escape character is the same in all the terms.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum