Java JDBC ResultSet:我需要一个 getDateTime,但只有 getDate 和 getTimeStamp
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21162753/
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
JDBC ResultSet: I need a getDateTime, but there is only getDate and getTimeStamp
提问by Tim
I would like to get the DATETIME column from an Oracle DB Table with JDBC. Here is my code:
我想从带有 JDBC 的 Oracle DB 表中获取 DATETIME 列。这是我的代码:
int columnType = rsmd.getColumnType(i);
if(columnType == Types.DATE)
{
Date aDate = rs.getDate(i);
valueToInsert = aDate.toString();
}
else if(columnType == Types.TIMESTAMP)
{
Timestamp aTimeStamp = rs.getTimestamp(i);
valueToInsert = aTimeStamp.toString();
}
else
{
valueToInsert = rs.getString(i);
}
I have to identify the column type first. The field I am interested in is recognized as a Types.DATE, but it is really a DATETIME in the DB since it has this format: "07.05.2009 13:49:32"
我必须首先确定列类型。我感兴趣的字段被识别为 Types.DATE,但它实际上是数据库中的 DATETIME,因为它具有以下格式:“07.05.2009 13:49:32”
getDate truncates the time: "07.05.2009" and getString appends ".0" to it: "07.05.2009 13:49:32.0"
getDate 截断时间:“07.05.2009”,getString 将“.0”附加到它:“07.05.2009 13:49:32.0”
Of course I could just remove the final .0 and work with getString all the time, but it is a dirty workaround.
当然,我可以删除最后的 .0 并一直使用 getString,但这是一个肮脏的解决方法。
Any ideas ? I was looking for a getDateTime method.
有任何想法吗 ?我正在寻找一个 getDateTime 方法。
Cheers, Tim
干杯,蒂姆
采纳答案by Leos Literak
java.util.Date date;
Timestamp timestamp = resultSet.getTimestamp(i);
if (timestamp != null)
date = new java.util.Date(timestamp.getTime()));
Then format it the way you like.
然后按照您喜欢的方式对其进行格式化。
回答by Basil Bourque
The answer by Leos Literakis correct but now outdated, using one of the troublesome old date-time classes, java.sql.Timestamp
.
Leos Literak的答案是正确的,但现在已经过时了,使用了麻烦的旧日期时间类之一java.sql.Timestamp
。
tl;dr
tl;博士
it is really a DATETIME in the DB
它实际上是数据库中的 DATETIME
Nope, it is not. No such data type as DATETIME
in Oracle database.
不,它不是。没有像DATETIME
Oracle 数据库那样的数据类型。
I was looking for a getDateTime method.
我正在寻找一个 getDateTime 方法。
Use java.timeclasses in JDBC 4.2 and later rather than troublesome legacy classes seen in your Question. In particular, rather than java.sql.TIMESTAMP
, use Instant
class for a moment such as the SQL-standard type TIMESTAMP WITH TIME ZONE
.
在 JDBC 4.2 及更高版本中使用java.time类,而不是在您的问题中看到的麻烦的遗留类。特别是,暂时不要java.sql.TIMESTAMP
使用Instant
类,例如 SQL 标准类型TIMESTAMP WITH TIME ZONE
。
Contrived code snippet:
人为的代码片段:
if(
JDBCType.valueOf(
myResultSetMetaData.getColumnType( … )
)
.equals( JDBCType.TIMESTAMP_WITH_TIMEZONE )
) {
Instant instant = myResultSet.getObject( … , Instant.class ) ;
}
Oddly enough, the JDBC 4.2 specification does not require support for the two most commonly used java.timeclasses, Instant
and ZonedDateTime
. So if your JDBC does not support the code seen above, use OffsetDateTime
instead.
奇怪的是,JDBC 4.2 规范并不要求支持两个最常用的java.time类Instant
和ZonedDateTime
. 因此,如果您的 JDBC 不支持上面看到的代码,请OffsetDateTime
改用。
OffsetDateTime offsetDateTime = myResultSet.getObject( … , OffsetDateTime.class ) ;
Details
细节
I would like to get the DATETIME column from an Oracle DB Table with JDBC.
我想从带有 JDBC 的 Oracle DB 表中获取 DATETIME 列。
According to this doc, there is no column data type DATETIME
in the Oracle database. That terminology seems to be Oracle's word to refer to all their date-time types as a group.
根据此文档,DATETIME
Oracle 数据库中没有列数据类型。该术语似乎是 Oracle 将所有日期时间类型称为一个组的词。
I do not see the point of your code that detects the type and branches on which data-type. Generally, I think you should be crafting your code explicitly in the context of your particular table and particular business problem. Perhaps this would be useful in some kind of generic framework. If you insist, read on to learn about various types, and to learn about the extremely useful new java.timeclasses built into Java 8 and later that supplant the classes used in your Question.
我没有看到您的代码检测数据类型的类型和分支的意义。通常,我认为您应该在特定表和特定业务问题的上下文中明确地编写代码。也许这在某种通用框架中会很有用。如果您坚持,请继续阅读以了解各种类型,并了解Java 8 和更高版本中内置的非常有用的新java.time类,这些类取代了您的问题中使用的类。
Smart objects, not dumb strings
智能对象,而不是哑字符串
valueToInsert = aDate.toString();
valueToInsert = aDate.toString();
You appear to trying to exchange date-time values with your database as text, as String
objects. Don't.
您似乎试图将日期时间值作为文本或String
对象与数据库交换。别。
To exchange date-time values with your database, use date-time objects. Now in Java 8 and later, that means java.timeobjects, as discussed below.
要与数据库交换日期时间值,请使用日期时间对象。现在在 Java 8 及更高版本中,这意味着java.time对象,如下所述。
Various type systems
各种类型系统
You may be confusing three sets of date-time related data types:
您可能会混淆三组与日期时间相关的数据类型:
- Standard SQL types
- Proprietary types
- JDBC types
- 标准 SQL 类型
- 专有类型
- JDBC 类型
SQL standard types
SQL标准类型
The SQL standard defines five types:
SQL 标准定义了五种类型:
DATE
TIME WITHOUT TIME ZONE
TIME WITH TIME ZONE
TIMESTAMP WITHOUT TIME ZONE
TIMESTAMP WITH TIME ZONE
DATE
TIME WITHOUT TIME ZONE
TIME WITH TIME ZONE
TIMESTAMP WITHOUT TIME ZONE
TIMESTAMP WITH TIME ZONE
Date-only
仅限日期
DATE
Date only, no time, no time zone.
DATE
只有日期,没有时间,没有时区。
Time-Of-Day-only
仅限时间
TIME
orTIME WITHOUT TIME ZONE
Time only, no date. Silently ignores any time zone specified as part of input.TIME WITH TIME ZONE
(orTIMETZ
)
Time only, no date. Applies time zone and Daylight Saving Time rules if sufficient data is included with input. Of questionable usefulness given the other data types, as discussed in Postgres doc.
TIME
或TIME WITHOUT TIME ZONE
仅时间,无日期。静默忽略指定为输入一部分的任何时区。TIME WITH TIME ZONE
(或TIMETZ
)
仅时间,无日期。如果输入中包含足够的数据,则应用时区和夏令时规则。考虑到其他数据类型的有用性,如Postgres doc 中所述。
Date And Time-Of-Day
日期和时间
TIMESTAMP
orTIMESTAMP WITHOUT TIME ZONE
Date and time, but ignores time zone. Any time zone information passed to the database is ignores with no adjustment to UTC. So this does notrepresent a specific momenton the timeline, but rather a range of possible moments over about 26-27 hours. Use this if the time zone or offset are (a) unknown or (b) irrelevant such as "All our factories around the world close at noon for lunch". If you have any doubts, not likely the right type.TIMESTAMP WITH TIME ZONE
(orTIMESTAMPTZ
)
Date and time with respect for time zone. Note that this name is something of a misnomer depending on the implementation. Some systems may store the given time zone info. In other systems such as Postgresthe time zone information is notstored, instead the time zone information passed to the database is used to adjust the date-time to UTC.
TIMESTAMP
或TIMESTAMP WITHOUT TIME ZONE
日期和时间,但忽略时区。任何传递到数据库的时区信息都将被忽略,不调整 UTC。因此,这也并不代表某个特定时刻的时间轴上,而是在大约26-27小时的范围可能的时刻。如果时区或偏移量 (a) 未知或 (b) 不相关,例如“我们在世界各地的所有工厂中午关闭午餐”,请使用此选项。如果您有任何疑问,可能不是正确的类型。TIMESTAMP WITH TIME ZONE
(或TIMESTAMPTZ
)
与时区相关的日期和时间。请注意,根据实现,此名称有点用词不当。某些系统可能会存储给定的时区信息。在其它系统中,例如Postgres的所述时区信息不存储,而不是传递到数据库的时区信息被用来调整日期时间为UTC。
Proprietary
所有权
Many database offer their own date-time related types. The proprietary types vary widely. Some are old, legacy types that should be avoided. Some are believed by the vendor to offer certain benefits; you decide whether to stick with the standard types only or not. Beware: Some proprietary types have a name conflicting with a standard type; I'm looking at you Oracle DATE
.
许多数据库提供自己的日期时间相关类型。专有类型差异很大。有些是应该避免的旧的遗留类型。供应商认为有些可以提供某些好处;您决定是否只使用标准类型。注意:某些专有类型的名称与标准类型相冲突;我在看着你OracleDATE
。
JDBC
JDBC
The Java platform's handles the internal details of date-time differently than does the SQL standard or specific databases. The job of a JDBC driveris to mediate between these differences, to act as a bridge, translating the types and their actual implemented data values as needed. The java.sql.* packageis that bridge.
Java 平台处理日期时间的内部细节与 SQL 标准或特定数据库不同。JDBC 驱动程序的工作是在这些差异之间进行调解,充当桥梁,根据需要转换类型及其实际实现的数据值。该的java.sql。*包是桥梁。
JDBC legacy classes
JDBC 遗留类
Prior to Java 8, the JDBCspec defined 3 types for date-time work. The first two are hacks as before Version 8, Java lacked any classes to represent a date-only or time-only value.
在 Java 8 之前,JDBC规范为日期时间工作定义了 3 种类型。前两个是版本 8 之前的 hack,Java 缺少任何类来表示仅限日期或仅限时间的值。
- java.sql.Date
Simulates a date-only, pretends to have no time, no time zone. Can be confusing as this class is a wrapper around java.util.Date which tracks both date andtime. Internally, the time portion is set to zero (midnight UTC). - java.sql.Time
Time only, pretends to have no date, and no time zone. Can also be confusing as this class too is a thin wrapper around java.util.Date which tracks both date andtime. Internally, the date is set to zero (January 1, 1970). - java.sql.TimeStamp
Date and time, but no time zone. This too is a thin wrapper around java.util.Date.
- java.sql.Date
模拟一个date-only,假装没有时间,没有时区。可能会令人困惑,因为此类是 java.util.Date 的包装器,它跟踪日期和时间。在内部,时间部分设置为零(UTC 午夜)。 - java.sql.Time
只有时间,假装没有日期,也没有时区。也可能令人困惑,因为这个类也是 java.util.Date 的一个瘦包装器,它跟踪日期和时间。在内部,日期设置为零(1970 年 1 月 1 日)。 - java.sql.TimeStamp
日期和时间,但没有时区。这也是一个围绕 java.util.Date 的瘦包装器。
So that answers your question regarding no "getDateTime" method in the ResultSet interface. That interface offers getter methodsfor the three bridging data types defined in JDBC:
这样就可以回答您关于ResultSet 接口中没有“getDateTime”方法的问题。该接口为JDBC 中定义的三种桥接数据类型提供了getter 方法:
getDate
for java.sql.DategetTime
for java.sql.TimegetTimestamp
for java.sql.Timestamp
getDate
对于 java.sql.DategetTime
对于 java.sql.TimegetTimestamp
对于 java.sql.Timestamp
Note that the first lack any concept of time zone or offset-from-UTC. The last one, java.sql.Timestamp
is always in UTC despite what its toString
method tells you.
请注意,第一个缺少时区或UTC偏移量的任何概念。最后一个,java.sql.Timestamp
不管它的toString
方法告诉你什么,总是在UTC 。
JDBC modern classes
JDBC 现代类
You should avoid those poorly-designed JDBC classes listed above. They are supplanted by the java.timetypes.
您应该避免上面列出的那些设计不佳的 JDBC 类。它们被java.time类型取代。
- Instead of
java.sql.Date
, useLocalDate
. Suits SQL-standardDATE
type. - Instead of
java.sql.Time
, useLocalTime
. Suits SQL-standardTIME WITHOUT TIME ZONE
type. - Instead of
java.sql.Timestamp
, useInstant
. Suits SQL-standardTIMESTAMP WITH TIME ZONE
type.
- 而不是
java.sql.Date
,使用LocalDate
。适合 SQL 标准DATE
类型。 - 而不是
java.sql.Time
,使用LocalTime
。适合 SQL 标准TIME WITHOUT TIME ZONE
类型。 - 而不是
java.sql.Timestamp
,使用Instant
。适合 SQL 标准TIMESTAMP WITH TIME ZONE
类型。
As of JDBC 4.2 and later, you can directly exchange java.timeobjects with your database. Use setObject
/getObject
methods.
从 JDBC 4.2 及更高版本开始,您可以直接与数据库交换java.time对象。使用setObject
/getObject
方法。
Insert/update.
插入/更新。
myPreparedStatement.setObject( … , instant ) ;
Retrieval.
恢复。
Instant instant = myResultSet.getObject( … , Instant.class ) ;
The Instant
class represents a moment on the timeline in UTCwith a resolution of nanoseconds(up to nine (9) digits of a decimal fraction).
该Instant
级表示时间轴上的时刻UTC,分辨率为纳秒(最多小数的9个位数)。
If you want to see the moment of an Instant
as viewed through the wall-clock time used by the people of a particular region (a time zone) rather than as UTC, adjust by applying a ZoneId
to get a ZonedDateTime
object.
如果您想Instant
通过特定地区(时区)的人们使用的挂钟时间而不是 UTC来查看 a 的时刻,请通过应用 aZoneId
来调整以获取ZonedDateTime
对象。
ZoneId zAuckland = ZoneId.of( "Pacific/Auckland" ) ;
ZonedDateTime zdtAuckland = instant.atZone( zAuckland ) ;
The resulting ZonedDateTime
object is the same moment, the same simultaneous point on the timeline. A new day dawns earlier to the east, so the date and time-of-day will differ. For example, a few minutes after midnight in New Zealand is still “yesterday” in UTC.
结果ZonedDateTime
对象是同一时刻,时间线上的同一同时点。新的一天在东方提前黎明,因此日期和时间会有所不同。例如,新西兰午夜后的几分钟在 UTC 中仍然是“昨天”。
You can apply yet another time zone to either the Instant
or ZonedDateTime
to see the same simultaneous moment through yet another wall-clock time used by people in some other region.
您可以将另一个时区应用于Instant
或ZonedDateTime
以通过其他地区的人们使用的另一个挂钟时间查看同一时刻。
ZoneId zMontréal = ZoneId.of( "America/Montreal" ) ;
ZonedDateTime zdtMontréal = zdtAuckland.withZoneSameInstant( zMontréal ) ; // Or, for the same effect: instant.atZone( zMontréal )
So now we have three objects (instant
, zdtAuckland
, zMontréal
) all representing the same moment, same point on the timeline.
所以现在我们有三个对象 ( instant
, zdtAuckland
, zMontréal
) 都代表同一时刻,时间线上的同一点。
Detecting type
检测类型
To get back to the code in Question about detecting the data-type of the databases: (a) not my field of expertise, (b) I would avoid this as mentioned up top, and (c) if you insist on this, beware that as of Java 8 and later, the java.sql.Types
class is outmoded. That class is now replaced by a proper Java Enum
of JDBCType
that implements the new interface SQLType
. See this Answerto a related Question.
回到关于检测数据库数据类型的问题中的代码:(a)不是我的专业领域,(b)我会避免上面提到的这种情况,以及(c)如果你坚持这个,当心从 Java 8 及更高版本开始,java.sql.Types
该类已经过时了。这个类现在用适当取代的JavaEnum
的JDBCType
实现了新的接口SQLType
。请参阅此对相关问题的回答。
This change is listed in JDBC Maintenance Release 4.2, sections 3 & 4. To quote:
此更改列在JDBC 维护版本 4.2 的第 3 和 4 节中。引用:
Addition of the java.sql.JDBCType Enum
An Enum used to identify generic SQL Types, called JDBC Types. The intent is to use JDBCType in place of the constants defined in Types.java.
添加 java.sql.JDBCType 枚举
用于标识通用 SQL 类型的 Enum,称为 JDBC 类型。目的是使用 JDBCType 代替 Types.java 中定义的常量。
The enum has the same values as the old class, but now provides type-safety.
枚举与旧类具有相同的值,但现在提供类型安全。
A note about syntax: In modern Java, you can use a switch
on an Enum
object. So no need to use cascading if-then statements as seen in your Question. The one catch is that the enum object's name must be used unqualified when switching for some obscure technical reason, so you must do your switch
on TIMESTAMP_WITH_TIMEZONE
rather than the qualified JDBCType.TIMESTAMP_WITH_TIMEZONE
. Use a static import
statement.
关于语法的注意事项:在现代 Java 中,您可以switch
在Enum
对象上使用 a 。因此,无需使用您的问题中所见的级联 if-then 语句。一个问题是,当由于某些晦涩的技术原因进行切换时,枚举对象的名称必须不加限定地使用,因此您必须使用switch
onTIMESTAMP_WITH_TIMEZONE
而不是限定的JDBCType.TIMESTAMP_WITH_TIMEZONE
. 使用static import
声明。
So, all that is to say that I guess (I've not tried yet) you can do something like the following code example.
所以,这就是说我猜(我还没有尝试过)您可以执行以下代码示例之类的操作。
final int columnType = myResultSetMetaData.getColumnType( … ) ;
final JDBCType jdbcType = JDBCType.valueOf( columnType ) ;
switch( jdbcType ) {
case DATE : // FYI: Qualified type name `JDBCType.DATE` not allowed in a switch, because of an obscure technical issue. Use a `static import` statement.
…
break ;
case TIMESTAMP_WITH_TIMEZONE :
…
break ;
default :
…
break ;
}
About java.time
关于java.time
The java.timeframework is built into Java 8 and later. These classes supplant the troublesome old legacydate-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
该java.time框架是建立在Java 8和更高版本。这些类取代了麻烦的旧的遗留日期时间类,例如java.util.Date
, Calendar
, & SimpleDateFormat
。
The Joda-Timeproject, now in maintenance mode, advises migration to the java.timeclasses.
现在处于维护模式的Joda-Time项目建议迁移到java.time类。
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
要了解更多信息,请参阅Oracle 教程。并在 Stack Overflow 上搜索许多示例和解释。规范是JSR 310。
You may exchange java.timeobjects directly with your database. Use a JDBC drivercompliant with JDBC 4.2or later. No need for strings, no need for java.sql.*
classes.
您可以直接与您的数据库交换java.time对象。使用符合JDBC 4.2或更高版本的JDBC 驱动程序。不需要字符串,不需要类。java.sql.*
Where to obtain the java.time classes?
从哪里获得 java.time 类?
- Java SE 8, Java SE 9, Java SE 10, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android (<26), the ThreeTenABPproject adapts ThreeTen-Backport(mentioned above). See How to use ThreeTenABP….
- Java SE 8、Java SE 9、Java SE 10及更高版本
- 内置。
- 具有捆绑实现的标准 Java API 的一部分。
- Java 9 添加了一些小功能和修复。
- Java SE 6和Java SE 7
- 多的java.time功能后移植到Java 6和7在ThreeTen-反向移植。
- 安卓
- 更高版本的 Android 捆绑实现 java.time 类。
- 对于早期的 Android(<26),ThreeTenABP项目采用了ThreeTen-Backport(上面提到过)。请参阅如何使用ThreeTenABP ...。
The ThreeTen-Extraproject extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.
该ThreeTen-额外项目与其他类扩展java.time。该项目是未来可能添加到 java.time 的试验场。你可能在这里找到一些有用的类,比如Interval
,YearWeek
,YearQuarter
,和更多。
UPDATE:The Joda-Timeproject, now in maintenance mode, advises migration to the java.timeclasses. This section left intact as history.
更新:现在处于维护模式的Joda-Time项目建议迁移到java.time类。这部分作为历史完好无损。
Joda-Time
乔达时间
Prior to Java 8 (java.time.* package), the date-time classes bundled with java (java.util.Date & Calendar, java.text.SimpleDateFormat) are notoriously troublesome, confusing, and flawed.
在 Java 8(java.time.* 包)之前,与 java 捆绑的日期时间类(java.util.Date & Calendar、java.text.SimpleDateFormat)是出了名的麻烦、混乱和有缺陷。
A better practice is to take what your JDBC driver gives you and from that create Joda-Time objects, or in Java 8, java.time.* package. Eventually, you should see new JDBC drivers that automatically use the new java.time.* classes. Until then some methods have been added to classes such as java.sql.Timestamp to interject with java.time such as toInstant
and fromInstant
.
更好的做法是采用 JDBC 驱动程序提供的内容,并从中创建 Joda-Time 对象,或者在 Java 8 中,java.time.* package。最终,您应该会看到自动使用新 java.time.* 类的新 JDBC 驱动程序。在此之前,一些方法已被添加到诸如 java.sql.Timestamp 之类的类中以与 java.time 插入,例如toInstant
和fromInstant
。
String
细绳
As for the latter part of the question, rendering a String… A formatter object should be used to generate a string value.
至于问题的后半部分,渲染一个字符串……应该使用一个格式化程序对象来生成一个字符串值。
The old-fashioned way is with java.text.SimpleDateFormat. Not recommended.
老式的方法是使用 java.text.SimpleDateFormat。不建议。
Joda-Time provide various built-in formatters, and you may also define your own. But for writing logs or reports as you mentioned, the best choice may be ISO 8601 format. That format happens to be the default used by Joda-Timeand java.time.
Joda-Time 提供了各种内置的格式化程序,您也可以定义自己的格式化程序。但是对于您提到的编写日志或报告,最好的选择可能是 ISO 8601 格式。该格式恰好是Joda-Time和 java.time使用的默认格式。
Example Code
示例代码
//java.sql.Timestamp timestamp = resultSet.getTimestamp(i);
// Or, fake it
// long m = DateTime.now().getMillis();
// java.sql.Timestamp timestamp = new java.sql.Timestamp( m );
//DateTime dateTimeUtc = new DateTime( timestamp.getTime(), DateTimeZone.UTC );
DateTime dateTimeUtc = new DateTime( DateTimeZone.UTC ); // Defaults to now, this moment.
// Convert as needed for presentation to user in local time zone.
DateTimeZone timeZone = DateTimeZone.forID("Europe/Paris");
DateTime dateTimeZoned = dateTimeUtc.toDateTime( timeZone );
Dump to console…
转储到控制台...
System.out.println( "dateTimeUtc: " + dateTimeUtc );
System.out.println( "dateTimeZoned: " + dateTimeZoned );
When run…
运行时…
dateTimeUtc: 2014-01-16T22:48:46.840Z
dateTimeZoned: 2014-01-16T23:48:46.840+01:00
回答by Nikolay Kombarov
this worked:
这有效:
Date date = null;
String dateStr = rs.getString("doc_date");
if (dateStr != null) {
date = dateFormat.parse(dateStr);
}
using SimpleDateFormat.
使用 SimpleDateFormat。
回答by Albizia
The solution I opted for was to format the date with the mysql query?:
我选择的解决方案是使用 mysql 查询格式化日期?:
String l_mysqlQuery = "SELECT DATE_FORMAT(time, '%Y-%m-%d %H:%i:%s') FROM uld_departure;"
l_importedTable = fStatement.executeQuery( l_mysqlQuery );
System.out.println(l_importedTable.getString( timeIndex));
I had the exact same issue.
Even though my mysql table contains dates formatted as such?: 2017-01-01 21:02:50
我有完全相同的问题。即使我的 mysql 表包含这样格式化的日期?:2017-01-01 21:02:50
String l_mysqlQuery = "SELECT time FROM uld_departure;"
l_importedTable = fStatement.executeQuery( l_mysqlQuery );
System.out.println(l_importedTable.getString( timeIndex));
was returning a date formatted as such?:
2017-01-01 21:02:50.0
正在返回一个这样格式化的日期?:
2017-01-01 21:02:50.0