标签:
1 特殊字符转义
通过jakarta commons lang 通用类包中(spring/lib/jakarta-commons/commons-lang.jar)的 StringEscapeUtils完成转义:
import org.apache.commons.lang.StringEscapeUtils; public class SqlEscapeExample { public static void main(String[] args) { String userName = "1‘ or ‘1‘=‘1"; String password = "123456"; userName = StringEscapeUtils.escapeSql(userName); password = StringEscapeUtils.escapeSql(password); String sql = "SELECT COUNT(userId) FROM t_user WHERE userName=‘" + userName + "‘ AND password =‘" + password + "‘"; System.out.println(sql); } }
标签:
原文地址:http://www.cnblogs.com/sunyt/p/4316153.html