首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql中特殊字符的处置

2012-11-06 
sql中特殊字符的处理在字符串工具StringUtils类中加入下面静态方法public static String filterSqlString(

sql中特殊字符的处理
在字符串工具StringUtils类中加入下面静态方法

public static String filterSqlString(String sqlStr) {        if (isEmpty(sqlStr)) {            return sqlStr;        }        sqlStr = sqlStr.replace("'", "''");        sqlStr = sqlStr.replace("/", "//");        sqlStr = sqlStr.replaceAll("%", "/%");        sqlStr = sqlStr.replaceAll("_", "/_");        return sqlStr;    }

在写sql时,按下面方式拼接字符串
a.SUBJECT like '%"+ StringUtils.filterSqlString(sqlStr)+ "%'escape '/' "

热点排行