Java – set the list parameter to native query
•
Java
I want to set the parameter to local query,
javax.persistence.EntityManager.createNativeQuery
Such a thing @ h_ 419_ 5@
Query query = em.createNativeQuery("SELECT * FROM TABLE_A a WHERE a.name IN ?"); List<String> paramList = new ArrayList<String>(); paramList.add("firstValue"); paramList.add("secondValue"); query.setParameter(1,paramList);
Attempting this query will result in an exception: @ h_ 419_ 5@
Caused by: org.eclipse.persistence.exceptions.DatabaseException: Internal Exception: com.MysqL.jdbc.exceptions.jdbc4.MysqLSyntaxErrorException: You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near '_binary'??\0♣sr\0‼java.util.ArrayListx??↔??a?♥\0☺I\0♦sizexp\0\0\0☻w♦\0\0\0t\0 f' at line 1 Error Code: 1064 Call: SELECT * FROM Client a WHERE a.name IN ? bind => [[firstValue,secondValue]] Query: ReadAllQuery(referenceClass=TABLE_A sql="SELECT * FROM TABLE_A a WHERE a.name IN ?")
Can I set list parameters for native queries instead of casting to strings and attaching them to SQL queries@ H_ 419_ 5@
Attachment: I use eclipse link 2.5 0 and MySQL server 5.6 13@H_419_5 @
Thank you @ h_ 419_ 5@
Solution
I believe you can only set the list parameter to jpql query, not native query
Use jpql, or use lists to dynamically construct SQL@ H_ 419_ 5@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码