对Prepared Statement 是否可以防止 SQL Injection 的实验
代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet; public class Test02 { public static void main(String argsv[]){
try
{
Class.forName("org.postgresql.Driver").newInstance();
String url = "jdbc:postgresql://localhost:5432/postgres" ; Connection con = DriverManager.getConnection(url,"postgres","postgres" ); ///Phase 1:-------------Select data from table-----------------------
System.out.println("Phase 1------------------------start"); String strsql = " select * from customers01 where cust_id = ?";
PreparedStatement pst=con.prepareStatement(strsql); pst.setString(,""); //find the customer with cust_id of 3. ResultSet rs = pst.executeQuery(); while (rs.next())
{
System.out.print("cust_id:"+rs.getInt( "cust_id"));
System.out.println("...cust_name:"+rs.getString( "cust_name" ));
}
System.out.println("Phase 1------------------------end\n"); rs.close();
pst.close();
con.close(); }
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
} }
如果我把 pst.setString(1,"3"); //find the customer with cust_id of 3. 改成:
pst.setString(1,"3 or 1 = 1"); 只是执行是无法得到结果而已,并未抓出所有记录。
prepared statement 还是相对的安全,它摒弃了sql语句的拼接。
对Prepared Statement 是否可以防止 SQL Injection 的实验的更多相关文章
- PHP MySQLi Prepared Statements Tutorial to Prevent SQL Injection
https://websitebeaver.com/prepared-statements-in-php-mysqli-to-prevent-sql-injection#introduction On ...
- How to prevent SQL injection attacks?
In our earlier tutorial on SQL Injection, one way to have prevented the SQL injection attack was by ...
- SQL injection
SQL injection is a code injection technique, used to attack data-driven applications, in which malic ...
- 防sql注入之参数绑定 SQL Injection Attacks and Defense
http://php.net/manual/zh/pdo.prepared-statements.php 预处理语句与存储过程 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作 ...
- 防sql注入之参数绑定 SQL Injection Attacks and Defense 预处理语句与存储过程
http://php.net/manual/zh/pdo.prepared-statements.php 预处理语句与存储过程 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作 ...
- Postgre cannot insert multiple commands into a prepared statement
悲剧... FireDAC连接Postgre数据库, 使用默认的属性, 一次执行多条SQL的时候, 会报"cannot insert multiple commands into a pre ...
- Postgresql:prepared statement "S_1" already exists
近期由于业务需要和一些json的存储查询需要,把新的应用切到pgsql上来,刚刚切好,是可以正常使用的,但是偶尔会来一下 java连接pgsql 偶尔出现 这个错. org.postgresql. ...
- Java向PostgreSQL发送prepared statement 与 libpq 向PostgreSQL发送prepared statement之比较:
Java 代码,在数据库端,并没有当成 prepared statetment 被处理. C代码通过libpq 访问数据库端,被当成了 prepared statement 处理.也许是因Postgr ...
- 网络攻击技术开篇——SQL Injection
本文转自: http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 摘要 日前,国内最大的程序员社区CSDN网站的用户数据库 ...
随机推荐
- MySQL数据库服务器安装标准
MySQL数据库服务器安装标准 (1).BIOS优化,阵列配置 1.1:关闭CPU节能,因为服务器品牌众多,BIOS设置不相同,主要是关闭CPU节能,如C1,DELLR730,已经智能设置,直接有个p ...
- pb 插入控件是出问题
http://m.blog.csdn.net/blog/jqz1225/34417493 是的http://blog.163.com/wufeng_1213/blog/static/167783313 ...
- vsphere client cd/dvd 驱动器1 正在连接
esxi 5.1选择了客户端设备,打开控制台后,CD/DVD一直显示“CD/DVD驱动器1 正在连接” 解决方法:vSphere Client客户端问题,关闭和重新打开vSphere Client客户 ...
- HashMap和Hashtable的区别(1)
导读: 1 HashMap不是线程安全的 hastmap实现了map接口,是将键映射到值的对象,其中键和值都是对象,并且不能包含重复键,但可以包含重复值.HashMap允许null key和null ...
- 函数buf_LRU_free_from_unzip_LRU_list
/******************************************************************//** Try to free an uncompressed ...
- bzoj1003: [ZJOI2006]物流运输
dp+最短路.暴力枚举就可以了.O(n3logn).样例中m=n然后测样例过了.然后 54行习惯性的dis[n]然后就WA了!!!. #include<cstdio> #include&l ...
- python auto send email
/*************************************************************************** * python auto send emai ...
- Oracle 数据库表空间碎片查询和整理
dba_free_space 显示的是有free 空间的tablespace ,如果一个tablespace 的free 空间不连续,那每段free空间都会在dba_free_space中存在一条记录 ...
- 【jQuery】jQuery操作<input>的聚焦与全选其内容
实现效果: 源代码: $(function() { $("#exist_code_remind").attr("style","display:non ...
- IE下设置unselectable与onselectstart属性的bug,Firefox与Chrome下的解决方案
在IE下给DIV设置unselectable与onselectstart属性,可以让div的内容不能选中,这个功能在很多情况下,非常有用,但是他的bug太明显, 直接使用一个DIV是可以的,比如: & ...