How does a PreparedStatement avoid or prevent SQL injection?

前端 未结 10 1858
再見小時候
再見小時候 2020-11-22 05:21

I know that PreparedStatements avoid/prevent SQL Injection. How does it do that? Will the final form query that is constructed using PreparedStatements will be a string or o

10条回答
  •  不要未来只要你来
    2020-11-22 05:27

    Prepared statement is more secure. It will convert a parameter to the specified type.

    For example stmt.setString(1, user); will convert the user parameter to a String.

    Suppose that the parameter contains a SQL string containing an executable command: using a prepared statement will not allow that.

    It adds metacharacter (a.k.a. auto conversion) to that.

    This makes it is more safe.

提交回复
热议问题