简体   繁体   中英

How to prevent sql injection in JPA

I am using below jpa code. How can we prevent below code from sql injections?

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

It already is protected against SQL injection. Your code is using parameters. Also if you want, you can use Criteria APIs to build the same query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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