随笔 - 118  文章 - 0 评论 - 0 阅读 - 2901
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

今天我对智能排班系统中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();
        }
    }
}
复制代码

 

posted on   满山猩猩我脸最黑  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示