当前位置:网站首页>mysql进阶(二十四)防御SQL注入的方法总结
mysql进阶(二十四)防御SQL注入的方法总结
2022-08-03 11:36:00 【InfoQ】
一、前言
二、演示下经典的SQL注入

select id,no from user where id=2;
String sql = "select id,no from user where id=" + id;
select id,no from user where id=2 or 1=1;

三、sql注入的原因
String sql = "select id,no from user where id=" + id;
or 1=1
where id=
四、sql注入的防御
String sql = "select id, no from user where id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, id);
ps.executeQuery();
PreparedStatement
select id, no from user where id=?
select ,from ,where ,and, or ,order by
String sql = "select id,no from user where id=" + id;
MySQLCodec codec = new MySQLCodec(Mode.STANDARD);
name = ESAPI.encoder().encodeForSQL(codec, name);
String sql = "select id,no from user where name=" + name;
ESAPI.encoder().encodeForSQL(codec, name)
五、总结
ibatis,mybatis,hibernate
ibatis/mybatis
#{name}
${name}
边栏推荐
猜你喜欢
FR9811S6 SOT-23-6 23V,2A同步降压DC/DC转换器
[论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly
asdn涨薪技术之apifox+Jenkins如何玩转接口自动化测试
[Star Project] Little Hat Plane Battle (9)
笔试题:金额拆分
【MySQL功法】第5话 · SQL单表查询
html网页如何获取后台数据库的数据(html + ajax + php + mysql)
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
What is the relationship between The Matrix and 6G?
随机推荐
[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly
第四周学习 HybridSN,MobileNet V1,V2,V3,SENet
[Explanation of JDBC and inner classes]
MySQL database combat (1)
后台图库上传功能
MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded
微信为什么使用 SQLite 保存聊天记录?
通过组策略安装软件和删除用户配置文件
微信小程序获取手机号
LeetCode——622.设计循环队列
下午见!2022京东云数据库新品发布会
ERC20通证标准是什么?
[Bubble sort and odd-even sorting]
【一起学Rust】Rust的Hello Rust详细解析
OFDM 十六讲 4 -What is a Cyclic Prefix in OFDM
Lease recovery system based on PHP7.2+MySQL5.7
Traceback (most recent call last): File
[Star Project] Little Hat Plane Battle (9)
FR9811S6 SOT-23-6 23V,2A同步降压DC/DC转换器
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结