Java SQLCODE -181 日期时间值的字符串表示不是有效的日期时间值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23242000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 21:28:53  来源:igfitidea点击:

SQLCODE -181 THE STRING REPRESENTATION OF A DATETIME VALUE IS NOT A VALID DATETIME VALUE

javadatabasedb2

提问by Dileepan

I'm getting " THE STRING REPRESENTATION OF A DATETIME VALUE IS NOT A VALID DATETIME VALUE" when I give 0001-01-01 00:00:00.000000for timestamp field from input. But when I change 0001to 0002given as 0002-01-01 00:00:00.000000for timestamp field from input, my code is working fine without any error. Why it is so? Will java not support 0001-01-01 00:00:00.000000value for timestamp?

当我0001-01-01 00:00:00.000000从输入中提供时间戳字段时,我得到“日期时间值的字符串表示不是有效的日期时间值” 。但是当我从输入更改00010002给定0002-01-01 00:00:00.000000的时间戳字段时,我的代码工作正常,没有任何错误。为什么会这样?java 不支持0001-01-01 00:00:00.000000时间戳值吗?

I'm using DB2 as my Database.

我使用 DB2 作为我的数据库。

回答by AngocA

In DB2, SQLCODE SQL0181 means that the given representation is not valid

在 DB2 中,SQLCODE SQL0181 表示给定的表示无效

db2 ? sql0181

However, when I write in DB2 your date, it accepts it:

但是,当我在 DB2 中写入您的日期时,它接受了它:

db2 "values timestamp('0001-01-01 00:00:00.000000')"

1
--------------------------
0001-01-01 00:00:00.000000

  1 record(s) selected.

However, when I put an invalid date, like 13 months, it returns your error code

但是,当我输入无效日期(例如 13 个月)时,它会返回您的错误代码

db2 "values timestamp('0001-13-01 00:00:00.000000')"

1
--------------------------
SQL0181N  The string representation of a datetime value is out of range.

I think you have a problem of locale and regional settings that does not correspond to the provided datetime.

我认为您的语言环境和区域设置与提供的日期时间不符。

Run this command, and then start modifying the date

运行这个命令,然后开始修改日期

db2 "values current timestamp"

Table 6. Datetime Limits

表 6. 日期时间限制

  • Smallest TIMESTAMP value 0001-01-01-00.00.00.000000000000
  • Largest TIMESTAMP value 9999-12-31-24.00.00.000000000000
  • 最小时间戳值 0001-01-01-00.00.00.000000000000
  • 最大 TIMESTAMP 值 9999-12-31-24.00.00.000000000000

http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0001029.html

http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0001029.html

回答by user2338816

There is a documented behavior related to a TIMESTAMP value of 0001-01-01 00:00:00.000000(as well as for 9999-12-31-24.00.00.000000000000) in JDBC/SQLJ for DB2. Not enough is known about the query itself, the code that submits the query, the column attributes, the DB2 version nor the platforms to tell how it might apply in this case.

在DB2 的 JDBC/SQLJ 中有与 TIMESTAMP 值0001-01-01 00:00:00.000000(以及 for 9999-12-31-24.00.00.000000000000)相关的记录行为。对查询本身、提交查询的代码、列属性、DB2 版本或平台的了解还不足以说明它在这种情况下如何应用。

Review the Use of PreparedStatement.setTimestamp to set values in TIMESTAMP WITH TIME ZONE columnstopic in the DB2 for z/OS Information Center, and pay attention to the descriptions relating to the particular timestamp values. The topic is about how the drivercan handle those values, though it doesn't really give much internal detail. I suspect that the driver is making a slight change to the query because it doesn't know the exact data type at the server.

查看DB2 for z/OS 信息中心中的使用 PreparedStatement.setTimestamp 设置 TIMESTAMP WITH TIME ZONE 列中的主题,并注意与特定时间戳值相关的描述。主题是关于驱动程序如何处理这些值,尽管它并没有真正提供太多内部细节。我怀疑驱动程序正在对查询进行轻微更改,因为它不知道服务器上的确切数据类型。

There are related data types that are possible. The driver might generate a slightly inappropriate SQLDA based on an assumption that gives the unexpected result.

有可能的相关数据类型。基于给出意外结果的假设,驱动程序可能会生成稍微不合适的 SQLDA。

It's likely that much more specific searches could find more info, but I don't know that an actual "answer" will be found without knowing a lot more about the driver internals. There will likely be very similar conditions found for any of the JDBC/SQLJ drivers depending on versions, etc. If this case isn't exactly about PreparedStatement.setTimestamp, it probably doesn't matter. There's bound to be related classes/methods using common code.

很可能更具体的搜索可以找到更多信息,但我不知道在不了解更多有关驱动程序内部的情况下会找到实际的“答案”。对于任何 JDBC/SQLJ 驱动程序,根据版本等可能会发现非常相似的情况。如果这种情况与 不完全有关PreparedStatement.setTimestamp,则可能无关紧要。肯定会有使用公共代码的相关类/方法。

回答by Dileepan

The problem is with the JDK version which i'm using,. In JDK 1.7 the default timestamp 0001-01-01 00.00.00.000000 is not supported, I changed my JDK from 1.7 to 1.6, and ran my program, the issue got resolved.

问题出在我使用的 JDK 版本上。在 JDK 1.7 中,不支持默认时间戳 0001-01-01 00.00.00.000000,我将 JDK 从 1.7 更改为 1.6,然后运行我的程序,问题得到解决。

If want to use JDK 1.7 then the default timestamp should be 0002-01-01 00:00:00.000000. In case of JDK 1.6 the default timesatmp is 0001-01-01 00:00:00.000000

如果要使用 JDK 1.7,则默认时间戳应为0002-01-01 00:00:00.000000. 在 JDK 1.6 的情况下,默认的 timesatmp 是0001-01-01 00:00:00.000000