Does using preparedStatement mean there will not be any SQL Injection?

前端 未结 5 1598
广开言路
广开言路 2021-02-20 10:58

I have read that to prevent SQL Injection one must use PreparedStatement.
Does that mean if i am using perparedStatement then no one can perform SQL Injection in any of my p

5条回答
  •  故里飘歌
    2021-02-20 11:32

    Although Prepared Statements helps in defending against SQL Injection, there are possibilities of SQL Injection attacks through inappropriate usage of Prepared Statements.

    The example below explains such a scenario where the input variables are passed directly into the Prepared Statement and thereby paving way for SQL Injection attacks.

    String strUserName = request.getParameter("Txt_UserName"); 
    PreparedStatement prepStmt = con.prepareStatement("SELECT * FROM user WHERE userId = '+strUserName+'");
    

    prepared statement can be vulnerable to SQL injection if it is not done properly.

提交回复
热议问题