I have created sample table in oracle DB as below
"CREATED_ON" TIMESTAMP (6),
"CREATED_ON_TIMEZONE" TIMESTAMP (6) WITH TIME ZONE,
"TIMEZONE_GMT" TIMESTAMP (6) WITH TIME ZONE
and inserted values from java as below
preparedStatement.setTimestamp(1, new Timestamp(new Date().getTime()));
preparedStatement.setTimestamp(2, new Timestamp(new Date().getTime()));
preparedStatement.setTimestamp(3, new Timestamp(new Date().getTime()) ,Calendar.getInstance(TimeZone.getTimeZone("UTC")));
JVM timezone in ASIA/CALCUTTA. I have used SQL developer to query data. I just wanted to clear my understanding
The first column stored value as per local JVM without timezone since dataType is only timestamp i.e 29-NOV-17 07.04.28.014000000 PM. so for column with timstamp datatype DB stores value as of local JVM which is passed by JDBC driver and there is no conversion happening either JDBC side or DB side ?
Second column store value with TIMEZONE i.e 29-NOV-17 07.04.28.014000000 PM ASIA/CALCUTTA. So does it mean DB stores value for column with timezone information provided by JDBC driver and there is no convrsion at DB side?
I want to store value in GMT so I set third parameter as GMT , it store value in GMT but timezone was still showing as of local JVM . i.e 29-NOV-17 01.34.28.014000000 PM ASIA/CALCUTTA
I was refering below article but my observations looks totally diffrent. http://brian.pontarelli.com/2011/08/16/database-handling-for-timezones/
TIMEZONE_GMT TIMESTAMP(6) GENERATED ALWAYS AS ( SYS_EXTRACT_UTC(CREATED_ON_TIMEZONE) ) VIRTUAL
resp.CREATED_ON TIMESTAMP(6) GENERATED ALWAYS AS ( CAST(CREATED_ON_TIMEZONE AS TIMESTAMP(6)) ) VIRTUAL
– Wernfried Domscheitoracle.sql.TIMESTAMPTZ
throughsetObject()
if you want to preserve the time zone. – a_horse_with_no_namejava.time
? If you can, skip the outdatedTimestamp
class. I believe you should saveLocalDateTime
objects into your timestamp column andInstant
objects into your timestamp with timezone columns. In both cases usePreparedStatement.setObject()
.java.time
is so much nicer to work with. – Ole V.V.