简体   繁体   English

如何防止JPA中的sql注入

[英]How to prevent sql injection in JPA

I am using below jpa code.我正在使用以下 jpa 代码。 How can we prevent below code from sql injections?我们如何防止下面的代码被 sql 注入?

List<Document> docs= em.createQuery("SELECT c FROM Document c WHERE c.docId = :docId ", Document.class)
                .setParameter("docId", docId).getResultList();

http://www.adam-bien.com/roller/abien/entry/preventing_injection_in_jpa_query http://www.adam-bien.com/roller/abien/entry/preventing_injection_in_jpa_query

It already is protected against SQL injection.它已经针对 SQL 注入进行了保护。 Your code is using parameters.您的代码正在使用参数。 Also if you want, you can use Criteria APIs to build the same query.此外,如果需要,您可以使用 Criteria API 来构建相同的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM