spring data jdbc - @query with like

Viewed 17

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.

1 Answers

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,'%')
Related