当前位置:网站首页>MySQL——SQL注入问题
MySQL——SQL注入问题
2022-07-03 21:02:00 【Java学不会】
1、SQL注入问题
- SQL存在漏洞,会被攻击导致数据泄露
2、PreparedStatement对象
PreparedStatement 可以防止SQL注入,效率更好
package demo; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Date; public class TestInsert01 { public static void main( String[] args ) { Connection conn = null; PreparedStatement st= null; try { conn=JdbcUtils.getConnection(); //使用? 占位符代替参数 String sql ="INSERT\tINTO users(`id`,`NAME`,`PASSWORD`,`email`,`birthday`) VALUES(?,?,?,?,?)"; st = conn.prepareStatement(sql); //手动给参数赋值 st.setInt(1,5); st.setString(2,"Java学不会"); st.setString(3,"123456"); st.setString(4,"[email protected]"); st.setDate(5,new java.sql.Date(new Date().getTime())); //执行 int i = st.executeUpdate(); if(i>0){ System.out.println("插入成功!"); } } catch (SQLException e) { e.printStackTrace(); }finally { JdbcUtils.release(conn,st,null); } } }
边栏推荐
- Line segment tree blue book explanation + classic example acwing 1275 Maximum number
- 2022 high voltage electrician examination and high voltage electrician reexamination examination
- How to set the system volume programmatically- How to programmatically set the system volume?
- QT6 QML book/qt quick 3d/ Basics
- 抓包整理外篇——————autoResponder、composer 、statistics [ 三]
- 18、 MySQL -- index
- 2022 low voltage electrician examination and low voltage electrician simulation examination question bank
- Design e-commerce seckill system
- Thread, thread stack, method stack, the difference of creating thread
- 19、 MySQL -- SQL statements and queries
猜你喜欢
JMeter plug-in installation
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028
设计电商秒杀系统
2022 safety officer-c certificate examination and safety officer-c certificate registration examination
"Designer universe" argument: Data Optimization in the design field ultimately falls on cost, safety and health | chinabrand.com org
强化学习-学习笔记1 | 基础概念
Rhcsa third day operation
Etcd 基于Raft的一致性保证
Study diary: February 14th, 2022
随机推荐
Is flush account opening and registration safe and reliable? Is there any risk?
Phpexcel import export
Sightseeing - statistics of the number of shortest paths + state transfer + secondary small paths
Summary of common operation and maintenance commands
How to choose cache read / write strategies in different business scenarios?
Pengcheng cup Web_ WP
Set, weakset, map, weakmap in ES6
Software testing skills, JMeter stress testing tutorial, obtaining post request data in x-www-form-urlencoded format (24)
@Transactional注解失效的场景
JMeter plug-in installation
[gd32l233c-start] 5. FLASH read / write - use internal flash to store data
Such as the visual appeal of the live broadcast of NBA Finals, can you still see it like this?
Hcie security Day11: preliminarily learn the concepts of firewall dual machine hot standby and vgmp
APEC industry +: father of the king of the ox mill, industrial Internet "king of the ox mill anti-wear faction" Valentine's Day greetings | Asia Pacific Economic media | ChinaBrand
运维各常用命令总结
Fingerprint password lock based on Hal Library
MySQL master-slave synchronization principle
TLS environment construction and plaintext analysis
Line segment tree blue book explanation + classic example acwing 1275 Maximum number
18、 MySQL -- index