简体   繁体   中英

JPA createNativeQuery with column name (and table name) as parameter

It is possible to set column name (or table name) as parameter in JPA, like :

   Query query = em.createNativeQuery(  "select ? , ? from ?");  
   query.setParameter(1, title); 
   query.setParameter(2, value); 
   query.setParameter(3, tableName); 

I got an SQL exception when running such code !! This code is used to get data from tables generated at runtime. It and do it with String concatenation, but what about setting parameters on query?

It is not possible, neither in this nor in any other sensible prepared statement implementation. The whole point of bind parameters is to separate code and data and a column is an identifier, thus "code".

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