Java DB 检查日期/时间字段(事件处理)?

发布于 2024-12-11 11:31:58 字数 98 浏览 8 评论 0原文

我如何在java中提出一种机制,可以监视Java DB表内的日期/时间字段,并且一旦一个或多个记录的日期/时间字段与系统时间匹配,我就可以获取它们进一步处理??!示例代码将不胜感激!

How can I come up with a mechanism in java where I could monitor the date/time fields inside a Java DB table and as soon as the the date/time fields for one or many of the records match the system time I could grab them for further processing??! Sample code would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞳孔里扚悲伤 2024-12-18 11:31:58

将数据库中的日期/时间字段设置为时间戳。然后从数据库中获取该字段的值。并将当前时间以毫秒为单位换算然后进行比较。

java.util.Date utilDate=new java.util.Date();
java.sql.Timestamp timest=new Timestamp(utilDate.getTime());

timest.compareTo(timest2);

Make date/time field in DB as Timestamp. Then get the value of this field from database. And convert the current time in millisecond and then compare.

java.util.Date utilDate=new java.util.Date();
java.sql.Timestamp timest=new Timestamp(utilDate.getTime());

timest.compareTo(timest2);
鹿! 2024-12-18 11:31:58

您当然可以使用触发器 - 这些是当特定事件发生时由 DBMS 自动执行的数据库过程,其中一个此类事件可能是日期/时间字段值的更改。

这些过程是在数据库本身中实现的,而不是在您的java代码中实现的。

这里是关于数据库触发器的维基百科文章。

You can surely use triggers - those are DB procedures that get executed by DBMS automatically, when a particular event arises, and one such event could be the change of the value of yours date/time fields.

Those procedires are implemented into DB itself, not into your java code.

Here is the wikipedia article on DB triggers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文