转:ibatis解决sql注入问题

对于ibaits参数引用可以使用#和$两种写法,其中#写法会采用预编译方式,将转义交给了数据库,不会出现注入问题;如果采用$写法,则相当于拼接字符串,会出现注入问题。

例如,如果属性值为“' or '1'='1 ”,采用#写法没有问题,采用$写法就会有问题。

对于like语句,难免要使用$写法,

 1. 对于Oracle可以通过'%'||'#param#'||'%'避免;

 2. 对于MySQL可以通过CONCAT('%',#param#,'%')避免;

 3. MSSQL中通过'%'+#param#+'% 。 

 

如下3种SQL语句:

[html]  view plain copy
  1. mysql: select * from t_user where name like concat('%',#name #,'%')    
  2.    
  3. oracle: select * from t_user where name like '%'||#name #||'%'   
  4.    
  5. SQL Server:select * from t_user where name like '%'+#name #+'%     

转自:http://blog.csdn.net/scorpio3k/article/details/7610973

扫描二维码关注公众号,回复: 1294548 查看本文章

猜你喜欢

转载自zuishengmengsi1990.iteye.com/blog/1874594