java 防sql注入 版本二

public class UtilGuoLv {

static String[] glcontext={"select","union","update","delete","insert",
"into","'","creat","and","where","1=1","1=2","/*",
"//","\\","///","/","\\\\","drop","lock table","grant","ascii",
"count","chr","mid","master","truncate"};

/**
* 强行过滤
* @param context  内容
* @param type   1String   2int
* @return
*/
public static String getContext(String context){
if(context==null)
{
return "";
}

for(int i=0;i<glcontext.length;i++){

if(context.indexOf(glcontext[i])!=-1){
context = context.replace(glcontext[i],"");
}

}

return context;
}
public static void main(String[] args) {
//System.out.println(com.wanhu.util.UtilGuoLv.getContext(null));
// System.out.println(main.glcontext);

//System.out.println(main.getContext("select fdjsklafjdskla fdsa fd sa fds a ''''''''',///,\\\\,\\,\\\\,////////,/*"));                                         

}

}

你可能感兴趣的:(java,sql)