ResultSet.getTimestamp("date")与ResultSet.getTimestamp("date",Calendar.getInstance(tz)) [英] ResultSet.getTimestamp("date") vs ResultSet.getTimestamp("date", Calendar.getInstance(tz))

查看:164
本文介绍了ResultSet.getTimestamp("date")与ResultSet.getTimestamp("date",Calendar.getInstance(tz))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.Datejava.util.Timetamp似乎给许多人造成了极大的困惑.在StackOverflow中,有很多问题,不幸的是我的问题有点扭曲.

java.util.Date, java.util.Timetamp were seems to be causing great confusion for many. Within StackOverflow there are so many questions, Unfortunately my question is bit twisted.

有2个JDBC API.他们应该如何表现? RDBMS之间是否存在一致性?

There are 2 JDBC api. How they should perform? Was there any consistencies among RDBMS’es?

ResultSet.getTimestamp("dateColumn") 
ResultSet.getTimestamp("dateColumn", Calendar.getInstance(tz))

如果某人对Sybase有知识,可以请您分享一下经验吗?

If someone has knowledge in Sybase, could you please share your experience?

推荐答案

首先,您将java.utiljava.sql混淆了.使用 java.sql.Date .类似,当使用 PreparedStatement#setTimestamp() java.sql.Timestamp .

First, you're confusing java.util with java.sql. When using PreparedStatement#setDate() and ResultSet#getDate(), you need java.sql.Date. Analogous, when using PreparedStatement#setTimestamp() and ResultSet#getTimestamp() you need java.sql.Timestamp.

第二,重要的是要理解java.sql.Date仅代表日期(年,月,日),而不代表更多或更少.这将被映射到SQL DATE字段类型. java.sql.Timestamp代表时间戳(年,月,日,小时,分钟,秒,毫秒),与

Second, it's important to understand that java.sql.Date represents solely the date (year, month, day) and nothing less or more. This is to be mapped to a SQL DATE field type. The java.sql.Timestamp represents the timestamp (year, month, day, hour, minute, second, millisecond), exactly as the java.util.Date and java.util.Calendar does. This is to be mapped to a SQL TIMESTAMP or DATETIME field type.

关于时区,当数据库不存储时区信息时(因此,所有时间戳都存储在UTC(GMT)中),您将需要它.然后,您可以传递Calendar,其中包含有关当前时区的信息,以便JDBC驱动程序可以将UTC时间戳调整为符合该时区的时间戳.例如,如果是GMT + 1,则JDBC驱动程序将在时间戳记上增加一小时,然后再返回.

As to the timezones, you need it when the database does not store timezone information (thus, all timestamps are stored in UTC (GMT)). You can then pass a Calendar in which contains information about the current timezone, so that the JDBC driver can adjust the UTC timestamp to the timestamp conforming the timezone. If it is for example GMT+1, then the JDBC driver will add one hour to the timestamp before returning.

这篇关于ResultSet.getTimestamp("date")与ResultSet.getTimestamp("date",Calendar.getInstance(tz))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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