I want to delete data from a mysql table if its with current date.
This is the code I wrote and is showing an exception at line “ERROR”:
What is the procedure to delete data from tables with a where condition applied?
Date date=new Date();
SimpleDateFormat myFormat=new SimpleDateFormat("dd-MM-yyyy");
String todayDate=myFormat.format(date);
String query="delete * from today_list where today_date="+"'"+todayDate+"'";
Transaction t1=session.beginTransaction();
session.createQuery(query).executeUpate();//ERROR
t1.commit();
According to SQL syntax you should not write
*afterdelete, i.e. change your statement todelete from ...Although it is not the right way when dealing with any ORM including Hibernate. This way bypasses cache (if you have cache). Better way is to delete entity using session API method.