今天我对智能排班系统中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(); } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】