bin
bin

Reputation: 33

How to convert a select statement in mysql into a query in java?

I have a select statement inside MySQL.

select * from tbl_user where path like '%,id,%'

How can I convert it to a query in Java? What I want to pass id.

Upvotes: 2

Views: 269

Answers (2)

袁文涛
袁文涛

Reputation: 856

maybe

@Query(value = "select * from tbl_user where path like CONCAT('%,',?1,',%')", nativeQuery = true) 
Iterable<Tbl_user> findAllChildUsers(int id);

will help

Upvotes: 3

Marek Borecki
Marek Borecki

Reputation: 440

It depends of what framework/library are you using. in hibernate you can use :id, but you have to also check that it is native query.

In some libraries you just pass a String as a query.

Upvotes: 0

Related Questions