Pregunta

I am trying to make a Java Thread, this thread have to delete from an MySQL database all the records, older than 7 days.

In my table i have a column that contain the date like this: 2013-10-28 17:00:00 .

And to do this i want to use JDBI library. and my question here if any one could give me and example of the query that i have to write.

I think it should look like this:

h.execute("Delete from  MyTable where date >= (dt.now.dayofmonth() -7)
¿Fue útil?

Solución

h.execute("DELETE FROM MyTable WHERE NOW() >= ADDDATE(date, INTERVAL 7 DAY);");

Otros consejos

Try this::

h.execute("Delete from  MyTable where DATEDIFF(CURDATE(), dateCOLUMN)>7");

"delete from MyTable where date >= date_sub(now(), interval 7 day)"

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top