In Spring Data JDBC, How I can write in CrudRepository a query with "like", I have try with this one, but it throws an error
@Query("select * from people p where name like :startOfName%")
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select * from people p where name like ?%]; SQL state [S0001]; error code [102]; Incorrect syntax near '%'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '%'.
I have seen this query in this topic for JpaRepository, but it is not working with spring data jdbc: %Like% Query in spring JpaRepository @Query("Select c from Registration c where c.place like %:place%").
Any ideas?
Thank you.
-
I know that the value of the parameter can have %, but is there any way to enforce the last %?javi_alt– javi_alt2022年09月17日 10:35:01 +00:00Commented Sep 17, 2022 at 10:35
1 Answer 1
Spring Data JDBC doesn't yet support this short syntax. You'll have to write full SQL statement:
select * from people p where name like concat(:startOfName,'%')