0

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.

javi_alt
  • 21
  • 3

1 Answers1

0

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,'%')
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348