The characters % and _ have special meaning in SQL LIKE clauses. You use % to match zero or more characters and _ to match exactly one character. If you want to interpret these characters literally in strings, then you precede them with a special escape character. For example, if you want to use ampersand (&) as the escape character, then you identify it in the SQL statement as:
Statement stmt = conn.createStatement ();
// Select the empno column from the emp table where the ename starts with ‘_’
ResultSet rset = stmt.executeQuery
(“SELECT empno FROM emp WHERE ename LIKE ‘&_%’ {ESCAPE ‘&’}”);
// Iterate through the result and print the employee numbers
while (rset.next ())
System.out.println (rset.getString (1));
Note:
If you want to use the backslash character (\) as an escape character, then you must enter it twice, that is, \\. For example:
ResultSet rset = stmt.executeQuery(“SELECT empno FROM emp
WHERE ename LIKE ‘\\_%’ {escape ‘\\’}”);
http://download-uk.oracle.com/docs/cd/B19306_01/java.102/b14355/apxref.htm#i1005208
