对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网站的用户数据库 ...
随机推荐
- 使用PHP处理POST上传时$_FILES数组为何为空
在做一个简单的表单上传测试时,服务端的php脚本中,$_FILES数组为空;这样就不能获取从浏览器上传的信息.什么原因呢? 通过Google,找到下面这个web: php上传文件$_FILES数组为空 ...
- git设置忽略某些文件或文件夹
在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改 .gitignore 文件的方法.如果没有 .gitignore 文件,就自己创建一个,手动创建会提示你输入文件名称,因此,你 ...
- 三个入侵的必备小工具-lcx.exe、nc.exe、sc.exe
lcx.exe的使用方法 以前抓肉鸡都是通过1433弱口令,然后.. 但是发现很多服务器开了1433,3389,但是终端是连不上的,因为服务器本身是在内网,只对外开放了1433端口,幸好有lcx. ...
- python项目
python实战项目: http://www.the5fire.com/category/python实战/ python基础教程中的十个项目: python项目练习一:即时标记 python项目练习 ...
- Codeforces Round #224 (Div. 2)
题目:http://codeforces.com/contest/382 A Ksenia and Pan Scales 一个求天平是否能够平衡的题目...水题,注意一下结果的输出就行. #inclu ...
- [ZOJ 2836] Number Puzzle
Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...
- [swustoj 327] 最小的最大与最大的最小
最小的最大与最大的最小(0327) Time limit(ms): 2500 Memory limit(kb): 65535 Submission: 329 Accepted: 18 问题描述 又 ...
- OK335xS can't reset with reboot
/*********************************************************************** * OK335xS can't reset * 说明: ...
- ToString() 格式化字符串
例如i=: i.ToString().PadLeft(,'); 固定长度为10,左不足补0,结果为0000000001:
- 在Linux运行期间升级Linux系统(Uboot+kernel+Rootfs)
版本:v1.2 Crifan Li 摘要 本文主要介绍了如何在嵌入式Linux系统运行的时候,进行升级整个Linux系统,包括uboot,kernel和rootfs.以及简介Linux中的已有的通 ...