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

前端 未结 5 1662
广开言路
广开言路 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

    Short answer: yes, if used properly.

    However, this does not mean that there can't be bugs in the JDBC driver, opening up for SQL injection. When I looked into this for a company I worked at, I found that there was indeed an SQL injection bug in one of the JDBC drivers we used (PostgreSQL). This is some years ago, and the bug was fixed.

    Although I don't remember the specifics, I recall looking at the source code for a JDBC implementation, and seeing that it was implemented with string concatenation.

    I would expect this to be rare, though, and my advice would be to trust the implementation and use PreparedStatements properly.

提交回复
热议问题