/**
* @Title:queryString
* @Description: 转义查询时输入'%'或者'_'
*
*
@author ql
*
@date 2014年9月26日 下午2:55:07
*
@param temp
* @return
*/
public static String queryString(String temp) {
if (temp == null || temp == "") {
return "";
}
StringBuilder b = new StringBuilder();
b.append(temp.trim());
StringBuilder tempBuilder = new StringBuilder();
tempBuilder.append(temp.trim());
for (int i = 0, j = 0; i < b.length(); i++) {
char x = b.charAt(i);
if (x == '%' || x == '_') {
tempBuilder.insert(i + j, '\\');
j++;
}
}
return tempBuilder.toString();
}
本文介绍了一种在SQL查询中处理特殊字符'%'和'_'的方法,通过使用转义字符''来避免语法错误,确保查询的正确执行。此技巧对于进行数据库操作时的字符串处理非常实用。
916

被折叠的 条评论
为什么被折叠?



