4

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?

3
  • 4
    You can not set table or column name by parameter Commented Mar 15, 2017 at 15:41
  • Why do you want to do string concatination. put the static values in the string Commented Mar 15, 2017 at 15:42
  • @Jens: Thank you Commented Mar 15, 2017 at 15:55

1 Answer 1

1

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".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.