JDBC 结果集 getDate 失去精度

发布于 2024-09-10 08:49:52 字数 231 浏览 1 评论 0原文

我在 ResultSet.getDate(x) 调用中失去了精度。基本上:

rs = ps.executeQuery();
rs.getDate("MODIFIED");

返回截断为 MODIFIED 是默认精度的 Oracle TIMESTAMP 字段的日期的日期。我认为我可能缺少一些 JDBC 调整;通常 TIMESTAMP 与 DATE 兼容,但我希望不必重新定义整个表。

I am losing precision in my ResultSet.getDate(x) calls. Basically:

rs = ps.executeQuery();
rs.getDate("MODIFIED");

is returning dates truncated to the day where MODIFIED is an Oracle TIMESTAMP field of default precision. I think there may be some JDBC tweak I'm missing; usually TIMESTAMP is compatible with DATE, but I'm hoping I don't have to redefine the entire table.

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

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

发布评论

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

评论(3

谎言月老 2024-09-17 08:49:52

ResultSet.getDate() 返回一个 java.sql.Date,而不是 java.util.Date。它被定义为一个永恒的日期。
如果您想要时间戳,请使用 <代码>ResultSet.getTimestamp()

ResultSet.getDate() returns a java.sql.Date, not a java.util.Date. It is defined to be a timeless date.
If you want a timestamp, use ResultSet.getTimestamp()!

淡淡的优雅 2024-09-17 08:49:52

您应该使用 java.sql.Timestamp 而不是 java.sql.Date。如果需要的话,您可以稍后将其用作 java.util.Date 对象。

rs = ps.executeQuery();
Timestamp timestamp = rs.getTimestamp("MODIFIED");

希望这有帮助。

You should use java.sql.Timestamp instead of java.sql.Date. You can use it as a java.util.Date object afterward if necessary.

rs = ps.executeQuery();
Timestamp timestamp = rs.getTimestamp("MODIFIED");

Hope this helps.

ぶ宁プ宁ぶ 2024-09-17 08:49:52

使用Timestap是正确的方法。
请注意,如果您要使用 Liquibase,则使用 Timestamp 将无法将列设置为可为空。

我也遇到过一个问题。

Using Timestap is the correct way.
Please take not that with Timestamp you will not be able to set the columns to nullable if you were to use Liquibase.

A problem I came across as well.

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