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.

asked Sep 17, 2022 at 0:19
1
  • I know that the value of the parameter can have %, but is there any way to enforce the last %? Commented Sep 17, 2022 at 10:35

1 Answer 1

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,'%')
answered Sep 19, 2022 at 11:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.