从JDBC ResultSet中将日期作为字符串读取时指定的日期格式在哪里 [英] Where is the date format specified when reading a date as a string from JDBC ResultSet

查看:130
本文介绍了从JDBC ResultSet中将日期作为字符串读取时指定的日期格式在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与从ResultSet中读取日期作为字符串时的默认JDBC日期格式,但该问题实际上从未真正得到回答;人们只是提供了编写代码的替代方法。

This is exactly the same question as Default JDBC date format when reading date as a string from ResultSet, but that question was never actually answered as such; people just offered alternative ways to write the code.

我特别询问是否有人知道指定默认转换格式的位置,以及是否由JDBC规范定义在某个地方,或者只是留给单独的JDBC驱动程序。如果是后者,那么另外一个问题是Oracle 10g JDBC如何做到这一点?

I'm specifically asking if anyone knows where the default conversion format is specified, and if it is defined by a JDBC spec somewhere, or just left up to the individual JDBC driver. If the latter, then an additional question of how does Oracle 10g JDBC do this?

**已添加15-Jan:

** Added 15-Jan:

对不起,我认为问题很清楚,但显然不是。我不是要从数据库中检索日期值,也不需要有关于如何做到这一点的建议。

Sorry, I thought the question was sufficiently clear, but apparently not. I am not trying to retrieve a date value from a database, and have no need for suggestions on ways to do that.

我不认为这是重复的引用的问题,这就是为什么我在这里问了一个单独的问题。虽然标题几乎相同,但引用的问题(无论OP意图是什么)已经用从数据库中检索日期值的替代方法得到了回答,这不是我想知道的。

I do not think this is a duplicate of the referenced question, which is why I asked a separate question here. Whilst the title is the pretty much same, the referenced question (regardless of what the OP intended) has been answered with alternative approaches for retrieving a date value from a database, which is not what I wish to know.

干杯,

推荐答案

好的,所以跟踪JDBC代码,它看起来像Oracle驱动程序硬编码自己的格式:

Ok, so tracing through the JDBC code, it looks like the Oracle driver hard-codes its own formatting:

  int k = (((bytes[0 + j] & 255) - 100) * 100 + (bytes[1 + j] & 255)) - 100;
  String s = k + "-" + toStr(bytes[2 + j])
      + "-" + toStr(bytes[3 + j])
      + " " + toStr(bytes[4 + j] - 1)
      + ":" + toStr(bytes[5 + j] - 1)
      + ":" + toStr(bytes[6 + j] - 1)
      + ".0";

因此,我猜测:


  1. 在任何JDBC规范中的任何地方都没有指定此行为。

  2. 每个驱动程序库都可以返回它喜欢的任何格式。

我假设这些是因为不同的实现返回不同的格式。当然,仍然可能在JDBC规范中的某处强制使用此格式,并且某些实现不符合要求,但这似乎不太可能。我当然在JDBC规范中找不到任何引用(但这并不意味着它们不在某处!)。

I'm assuming these because different implementations return different formats. Of course, it is still possible that this format is mandated somewhere in a JDBC spec, and some implementations are non-conformant, but that seems unlikely. I certainly couldn't find any references to this in a JDBC spec (but that doesn't mean they are not there somewhere!).

然而,关键点是就我而言,格式是在库中进行硬编码,不能被任何环境或其他设置覆盖,但只要驱动程序库版本保持不变,也不会在系统中进行更改。

However, the key point as far as I am concerned, is that the format is hard-coded in the library and not overridable by any environment or other settings, but also won't change across systems as long as the driver library version remains the same.

这篇关于从JDBC ResultSet中将日期作为字符串读取时指定的日期格式在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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