spring simplejdbctemplate sql语句中特殊字符怎么转义
1个回答
展开全部
package com.baobaotao.escape;
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);
}
}
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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询