[英]Creating event to delete records in the table
I am trying to get my mysql event to work but I am facing problem that the bus table is being created without the autoDelete
event and I am not getting any error. 我正在尝试使我的mysql事件正常工作,但是我遇到的问题是正在创建没有
autoDelete
事件的总线表,并且没有出现任何错误。 I checked my table in phpmyadmin by executing this statement show events
in the sql browser I am getting the result empty results
as I said the bus table is there?! 我通过在SQL浏览器中执行以下语句
show events
在phpmyadmin中检查了我的表,因为我说总线表在那里,所以我得到的结果为empty results
?
I checked the EVENT syntax code in the phpmyadmin sql browser and it works? 我在phpmyadmin sql浏览器中检查了EVENT语法代码,它有效吗?
DatabaseMetaData dbm = con.getMetaData();
ResultSet tables = dbm.getTables(null, null, "bus", null);
if (tables.next()) {
// here if the table exist just update data. I have the most of my code her.
return status;
} else {
// Create bus table
stt.execute("CREATE TABLE IF NOT EXISTS bus"
+ "(id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
+ "mac VARCHAR(30) NOT NULL UNIQUE,"
+ "route int(11) NOT NULL,"
+ "latitude FLOAT(10,6) NOT NULL,"
+ "longitude FLOAT(10,6) NOT NULL,"
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
stt.execute("CREATE EVENT AutoDelete"
+ "ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE "
+ "DO "
+ "DELETE FROM bus WHERE created_at < (NOW() - INTERVAL 3 MINUTE)");
insert_update_data(mac, route, latD, longD, con);
return status;
}
Try putting space after the event name 尝试在事件名称后放置空格
"CREATE EVENT AutoDelete "
I think your code is currently creating a string that looks like : 我认为您的代码当前正在创建一个类似于以下内容的字符串:
CREATE EVENT AutoDeleteON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE DO DELETE FROM bus WHERE created_at < (NOW() - INTERVAL 3 MINUTE)
Although I am surprised that this didn't throw a SQLException 虽然我很惊讶这没有引发SQLException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.