1

I have 2 columns in my table with data type TIMESTAMP and DATE. The column with data type "DATE" is default date/time, so that we don't need to insert from JAVA, It automatically gets inserted. For the other column with data type "TIMESTAMP" I manually insert the current time from JAVA which is optional. The actual problem is the database time differs from the time which I insert from java. ie.The default time inserted is not same as the date/time which I manually inserted from DB. Is there any way to match the database time to system time which is inserted from java? The SQL date differs by 7-8 minutes from my system date, which should get matched while inserting it manually.

Kishor kumar R
  • 195
  • 2
  • 17

1 Answers1

0

If you want to insert current_date in both mentioned columns and you are unable to do so:

Check if your system's (where java code is running) timezone and database's timezone are same.

In database run this query:

SELECT dbtimezone FROM DUAL;

and if you find it different from your java/system then you can always change it using :

ALTER DATABASE SET TIME_ZONE='+05:30'; 

https://docs.oracle.com/cd/E11882_01/server.112/e10729/ch4datetime.htm#NLSPG263

EDIT 1: If you don't want to change the timezone you can do two things:

1) select the date/time form database in java instead of taking it from Calendar object. Then insert the same date/time to TIMESTAMP column. display timestamp value in java from database

2) set database DATE field from java instead of database itself. So apparently setting both the fields from java. http://alvinalexander.com/java/java-timestamp-example-current-time-now

R Dhaval
  • 536
  • 1
  • 9
  • 21
  • I should not change the system or db time as i could deploy the same project in some other environment. But database date should gets matched with the environment date. Is that possible? – Kishor kumar R Jun 05 '17 at 05:20
  • yeah this is one solution. But considering the performance don't we have any other options? – Kishor kumar R Jun 05 '17 at 15:12