Reputation: 301
Below is the simple example which explain my problem
Query(name = "select p.* , pr.actual_date_time , count(*) " +
"from player p " +
"inner join app.player_reports pr ON pr.player_id = p.id " +
"where pr.actual_date_time between now() - interval '?1 day'
and now() - interval '0 day' " ,nativeQuery = true)
List<PlayerEntity> findCheaters(@param("NumberDays") int number )
this is my query, I want to put "NumberDays" between single quotation and substitute with "?1".
I would be glad to help me, and thank you
Upvotes: 4
Views: 1226
Reputation:
You can't parametrize the value for the interval constant, but you can simply multiply the base unit with a parameter:
pr.actual_date_time between now() - (interval '1 day' * ?) and now()
Then pass the number of days you want as an integer to the PreparedStatement.
Note that the - interval '0 day'
is useless
Upvotes: 2