gpt4 book ai didi

MYSQL 数据库中插入或替换为空时的 Java 消息

转载 作者:行者123 更新时间:2023-11-30 00:26:51 25 4
gpt4 key购买 nike

我使用解析器从文本文件中读取数据并将其写入数据库。我想找到一种方法,当读数为空超过2次时,发送错误消息。

我该怎么做?

这可能吗?

我希望我已经明确表示怀疑。

如果有人不明白请我澄清。

感谢您的帮助。

解析器的代码是:

BufferedReader reader = new BufferedReader(new FileReader("C:/Users/RPR1BRG/Desktop/test.txt"));

String dados[] = new String[6];
String linha = reader.readLine();

while (linha != null) {

StringTokenizer st = new StringTokenizer(linha, ";\"");

dados[0] = st.nextToken();
dados[1] = st.nextToken();
dados[2] = st.nextToken();
dados[3] = st.nextToken();
dados[4] = st.nextToken();
dados[5] = st.nextToken();

DateFormat dateFormat = new SimpleDateFormat("d-M-yy");

PreparedStatement stmt = (PreparedStatement) conexao.prepareStatement("replace into registos" + " (date, hour, Id, Tem, Hum, pt) values (?,?,?,?,?,?)");

try {
stmt.setDate(1, new java.sql.Date(dateFormat.parse(dados[0]).getTime()));
stmt.setString(2, dados[1]);
stmt.setString(3, dados[2]);
stmt.setString(4, dados[3]);
stmt.setString(5, dados[4]);
stmt.setString(6, dados[5]);

} catch (java.text.ParseException ex) {
Exceptions.printStackTrace(ex);
}

stmt.executeUpdate();

最佳答案

Do you mean that, if with an interval of 30 minutes each, if a file is read twice in an hour, and if these successive readings found an empty file, then a warning action has to be fired. Is that right? – Ravinder

Yes that is exactly what happens. I dont know is how to create warning The function to read file is executed within a timer function... – user3320956

解决方案:

Timer实现类中,定义

  1. lastReadTime - 保存上次读取文件的时间。
  2. timeDiff - 保存从上次读取到当前时间的时间差。
  3. 如果间隔约为 30 分钟,则设置警告消息。
  4. 定义并调用刚刚出现的publishWarningMessage方法。发布可以保存到数据库中或通过短信/电子邮件/...等方式发送,具体取决于您的要求。
  5. 继续或等到下一次阅读。

关于MYSQL 数据库中插入或替换为空时的 Java 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22808066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com