Reputation: 5594
oracle db JDBC:
select current_date from dual
It returns a java.sql.Timestamp, not java.sql.Date instance.
select current_timestamp from dule
It returns a oracle.sql.TIMESTAMPTZ, not java.sql.Timestamp instance.
How to make them return values of JDBC java.sql.* standard types?
Upvotes: 0
Views: 1281
Reputation: 168096
In Oracle, a DATE
data type has year, month, day, hour, minute and second components.
In Java:
java.sql.Date
class has year, month and day components.java.sql.Timestamp
class has year, month, day, hour, minute and second components.The correct Java data type for an Oracle DATE
is java.sql.Timestamp
and not java.sql.Date
(you can use java.sql.Date
as the return value from stored procedures, etc. but it will truncate the time components).
In Oracle, CURRENT_TIMESTAMP
has the data type TIMESTAMP WITH TIME ZONE
. In Java, this is the equivalent of oracle.sql.TIMESTAMPTZ
class.
Upvotes: 1
Reputation: 6233
Oracle SQL returns Oracle data types. You can use trunc(current_date) to get rid of the time part (not that it will affect the return type, though!). However, to get the right data type with JDBC, simply use the proper get method in https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html. The getDate
method returns a java.sql.Date
, the getTimestamp
method returns a java.sql.Timestamp
.
Upvotes: 0