插入最大日期(独立于数据库) [英] Insert the max date (independent from database)

查看:109
本文介绍了插入最大日期(独立于数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地设置中,我使用的是简单的H2数据库。 托管解决方案将具有另一个(类似但不相同)数据库。

In my local setup i'm using a simple H2 databse. The "hosted" solution will have another (similar but not same) database.

我需要将最大可能日期插入DateTime列。我试图使用

I need to insert the maximum possible date into a DateTime column. I tried to use

Instant.MAX

然而,这导致-169104626-12-11 20:08:15.99999999在列中。

However this results in -169104626-12-11 20:08:15.99999999 in the column.

是否有可靠的选项如何插入最大可能日期?

Is there a solid option on how to insert a maximum possible date?

推荐答案


最大日期(独立于数据库)

max date (independent from database)

没有这样的事情。尝试设置最大日期完全取决于数据库。

No such thing. Trying to set a maximum date is absolutely dependent on the database.

SQL标准(遗憾的是)几乎没有涉及日期时间处理的主题。日期时间的数据类型和行为在各种数据库中广泛地 。各种数据库之间的最小值和最大值可能完全不同。即使在单个数据库中,各种日期时间数据类型的最小/最大范围也可能大不相同。例如,某些数据库具有旧的专有日期时间类型以及更新的更常见或标准类型,其行为完全不同。

The topic of date-time handling is barely touched by the SQL standard (unfortunately). The data types and behavior for date-time vary widely amongst various databases. The minimum and maximum values can be radically different between various databases. Even within a single database, the min/max range of the various date-time data types can be dramatically different. For example, some databases have old proprietary date-time types as well as newer more common or standard types that behave quite differently.

Java本身具有非常不同的日期集 - 时间类型:

Java itself has very different sets of date-time types:


  • 麻烦的遗留类型(java.util& java.sql)

  • 现代明智设计的 java.time 类型。

  • The troublesome legacy types (java.util & java.sql)
  • The modern wisely-designed java.time types.

这些的最小值/最大值不同。

The min/max of these differ.


是否有关于如何插入最大可能日期的可靠选项?

Is there a solid option on how to insert a maximum possible date?

否。

如果您尝试使用最大值作为某种标志,例如未确定的未来日期以避免NULL,而是在将来选择一些足够远的任意日期来超过任何合法值,但不要超过您可能要使用的任何数据库的限制。在Java代码和数据库中为此值定义一个常量,并彻底记录。

If you are trying to use the maximum value as some kind of flag such as "undetermined future date" to avoid a NULL, instead choose some arbitrary date far enough in the future to exceed any legitimate value but not so far as to exceed the limits of any database you are possibly going to use. Define a constant for this value in your Java code and in your database, and document thoroughly.

我建议坚持使用四位数年份以避免各种混淆和打破报告等问题通过超出字段的显示宽度的GUI。像 9999 之类的东西。或者 2666 ,因为 infamy of 666

I suggest sticking with a four-digit year to avoid all kinds of confusion and problems such as breaking reports & GUIs by exceeding the field’s width of display. Something like 9999. Or perhaps 2666 because it is so noticeable to the human reader due to the infamy of 666.

搜索Stack Overflow,例如Java,min和max,以获得更多讨论。与这个这个。这个问题基本上与其他问题重复。

Search Stack Overflow for words such as Java, min, and max, for more discussion. Like this and this and this and this and this. This question is basically a duplicate of other Questions.

这篇关于插入最大日期(独立于数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆