英文:
TIMESTAMP WITH TIME ZONE vary between OJDBC6 and OJDBC8
问题
我在使用 OJDBC8 时遇到了问题。不久前,我决定从 OJDBC6 切换到 OJDBC8,之前正常工作的一些功能停止了工作。我有一个带有 GMT-4 和所有其他属性的日历对象。当我在使用 OJDBC6 时,下面的代码可以正常运行,时间戳会根据时区进行调整。
rs.getTimestamp(1, calendar)
当我使用 OJDBC8 并使用与上述相同的代码时,时间戳不会调整,基本上时间戳不会改变,它的值与数据库中的相同。我已经检查了 OJDBC8 的代码,并且版本 6 和 8 之间的逻辑是不同的。我不明白为什么我们将日历对象传递给 getTimestamp() 方法,但在 OJDBC8 中却没有使用它。
英文:
I do have a problem with OJDBC8. Sometime ago I decided to switch from OJDBC6 -> OJDBC8 and some of the functionality that worked before stopped working. I have a Calendar object with GMT-4 and all other properties. When I am using OJDBC6 this code below works fine, the TIMESTAMP is adjusted to the time zone.
rs.getTimestamp(1, calendar)
When using OJDBC8 and the same code as above the timestamp isn't adjusted, basically the timestamp does not change it has the same value as in the database. I've checked the OJDBC8 code and the logic is different between version 6&8. I do not understand why we pass calendar object to getTimestamp() method but it isn't even used in OJDBC8.
答案1
得分: 1
请注意,ojdbc8
的 Java 编译器级别为 Java-8,而ojdbc6
的级别为 Java-6。Java-8 引入了 全新的日期时间 API。传统的日期时间 API (java.util
) 容易出错,使用它们的代码通常复杂且难以理解。
您应该使用现代的日期时间 API (java.time
),操作如下:
OffsetDateTime odt = rs.getObject(1, OffsetDateTime.class);
从 Trail: Date Time 了解有关现代日期时间 API 的更多信息。
为了切换到现代日期时间 API,您所做的更改将是值得的,而且将有助于长期的开发。
英文:
Note that the Java compiler level for ojdbc8
was Java-8 while that for ojdbc6
was Java-6. With Java-8, a completely new date-time API was introduced. The legacy date-time API (java.util
) was error-prone and the code using them used to be complex and difficult to understand.
You should use the modern date-time API (java.time
) and do it as follows:
OffsetDateTime odt = rs.getObject(1, OffsetDateTime.class);
Learn more about the modern date-time API from Trail: Date Time
The changes you will make in order to switch to the modern date-time API will be worth and will help you in the long-term.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论