Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace table name with parameter value while using Spring Data JPA nativeQuery

like this:

public interface XXXRepository extends CrudRepository<XXX, Integer> {
@Query(value = "select * from ?1 where ...", nativeQuery = true)
List<XXX> findByXXX(String tableName, ...);}

It gives MYSQL syntax error with upon codes. The syntax error shows that the table name in the SQL is surrounded with "'".

like image 417
Jason Avatar asked Oct 16 '25 01:10

Jason


1 Answers

This is not possible. Parameters are only allowed in the where clause.

like image 80
Simon Martinelli Avatar answered Oct 17 '25 14:10

Simon Martinelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!