代码:

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 的实验的更多相关文章

  1. PHP MySQLi Prepared Statements Tutorial to Prevent SQL Injection

    https://websitebeaver.com/prepared-statements-in-php-mysqli-to-prevent-sql-injection#introduction On ...

  2. How to prevent SQL injection attacks?

    In our earlier tutorial on SQL Injection, one way to have prevented the SQL injection attack was by ...

  3. SQL injection

    SQL injection is a code injection technique, used to attack data-driven applications, in which malic ...

  4. 防sql注入之参数绑定 SQL Injection Attacks and Defense

    http://php.net/manual/zh/pdo.prepared-statements.php 预处理语句与存储过程 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作 ...

  5. 防sql注入之参数绑定 SQL Injection Attacks and Defense 预处理语句与存储过程

    http://php.net/manual/zh/pdo.prepared-statements.php 预处理语句与存储过程 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作 ...

  6. Postgre cannot insert multiple commands into a prepared statement

    悲剧... FireDAC连接Postgre数据库, 使用默认的属性, 一次执行多条SQL的时候, 会报"cannot insert multiple commands into a pre ...

  7. Postgresql:prepared statement "S_1" already exists

    近期由于业务需要和一些json的存储查询需要,把新的应用切到pgsql上来,刚刚切好,是可以正常使用的,但是偶尔会来一下 java连接pgsql 偶尔出现 这个错.   org.postgresql. ...

  8. Java向PostgreSQL发送prepared statement 与 libpq 向PostgreSQL发送prepared statement之比较:

    Java 代码,在数据库端,并没有当成 prepared statetment 被处理. C代码通过libpq 访问数据库端,被当成了 prepared statement 处理.也许是因Postgr ...

  9. 网络攻击技术开篇——SQL Injection

    本文转自: http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 摘要 日前,国内最大的程序员社区CSDN网站的用户数据库 ...

随机推荐

  1. VMware Workstation与Hyper-V不兼容。请先从系统中移除Hyper-V角色,然后再运行VMware Workstation。

    VMware Workstation与Hyper-V不兼容.请先从系统中移除Hyper-V角色,然后再运行VMware Workstation. 今天在用win8.1的时候发现了这个问题,解决办法如下 ...

  2. WINCE6.0 error C2220: warning treated as error问题解决

    今天在编译IMX515的BSP的时候,发现下面的编译错误问题: BUILD: [00:0000002476:PROGC ] BuildingCOMPILE Pass in F:\WINCE600\PL ...

  3. Convert boolean values to strings 'Yes' or 'No'.

    Convert boolean values to strings 'Yes' or 'No'. Complete the bool_to_word (Javascript: boolToWord ) ...

  4. [原]Unity3D深入浅出 - 粒子系统(Particle System)

    粒子系统是在三维空间渲染出来的二维图像,主要用于烟,火,水滴,落叶等效果.一个粒子系统由粒子发射器.粒子动画器和粒子渲染器三个独立的部分组成. Unity中自带了一些粒子效果,在Assets>I ...

  5. Entityframework常用命令

    Enable-Migrations 启用Migration数据迁移 Add-Migration migrationname 添加一个migration Update-Database –TargetM ...

  6. UVa 673 (括号配对) Parentheses Balance

    本来是当做水题来做的,后来发现这道题略坑. 首先输入的字符串可能是空串,所以我用了gets函数,紧接着就被scanf("%d", &n)后面的换行符坑掉了. 于是乎再加一句 ...

  7. C# 判断两张图片是否一致的快速方法

    #region 判断图片是否一致 /// <summary> /// 判断图片是否一致 /// </summary> /// <param name="img& ...

  8. Host绑定

    Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Host ...

  9. ubuntu常用快捷键

    1.直接退出窗口  Ctrl + q 2.窗口变大变小  Alt + Q 3.最小化窗口,显示桌面Ctrl + Alt + D 4.把当前窗口移到另一个工作区 Shift+ Ctrl + Alt +方 ...

  10. .Net 垃圾回收机制原理(二)

    英文原文:Jeffrey Richter 编译:赵玉开 链接http://www.cnblogs.com/yukaizhao/archive/2011/11/25/dot_net_GC_2.html ...