6.1
今天我对智能排班系统中Android端进行了爆红代码修复以及,在数据库中创建了trggier表实现数据表中数据的的监听,并且使用notifaction方法实现弹窗提示功能。
CREATE TABLE android_notification ( id INT NOT NULL AUTO_INCREMENT, title VARCHAR(50) NOT NULL, message TEXT, notification_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=InnoDB;
USE test;
CREATE TRIGGER test_one_trigger AFTER UPDATE ON test_one FOR EACH ROW
BEGIN
IF NEW.time != OLD.time OR NEW.from_to != OLD.from_to THEN
UPDATE android_notification SET message = ' ' WHERE id = 1;
END IF;
END;
public class MySQLNotificationManager {
private Connection connection;
public MySQLNotificationManager(Connection connection) {
this.connection = connection;
}
public void listen() {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE IF EXISTS android_notification");
statement.execute("CREATE TABLE android_notification (id INT, message VARCHAR(50))");
statement.execute("INSERT INTO android_notification (id, message) VALUES (1, '')");
CallableStatement cs = connection.prepareCall("{ ? = call mysql_listen(?,?,?) }");
cs.registerOutParameter(1, Types.INTEGER);
cs.setString(2, "host");
cs.setInt(3, port);
cs.setString(4, "database");
cs.execute();
int status = cs.getInt(1);
if (status == 1) {
while (true) {
ResultSet rs = statement.executeQuery("SELECT message FROM android_notification WHERE id = 1");
if (rs.next()) {
String message = rs.getString("message");
if (!message.isEmpty()) {
// 处理通知窗口
}
}
Thread.sleep(1000);
}
}
} catch (SQLException | InterruptedException e) {
e.printStackTrace();
}
}
}

浙公网安备 33010602011771号