skip to Main Content

With spring boot, I want to delete data greater than 48 hours in the
database with a sql query.

I want to delete data in database more than 48 hours.

DELETE FROM schedule WHERE date_time < NOW() - INTERVAL 48 HOUR;

This query works fine in mysql, but I want to do it in spring boot.

@Query("DELETE FROM schedule WHERE date_time < NOW() - INTERVAL 48 HOUR")

i do it this way but i get error (‘(‘, or expected, got ’48’)

2

Answers


  1. i think this one will be helpful,

    @Query(value = "DELETE FROM schedule WHERE date_time < NOW() - INTERVAL 48 HOUR", nativeQuery = true)
    
    Login or Signup to reply.
  2. Or you can use hibernate query language(HQL) instead of native query

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search