-3

Recently we upgraded java runtime environment in UNIX from jdk 1.4 to jdk 8. What we found is, the date that is getting inserted in oracle database is with timestamp (dd-mm-yyyy hh:mm:ss). Before upgrade, it was only date (dd-mm-yyyy). Is this is due to jdk upgrade. Same build is used which was running in JDK 1.4 after upgrading to JDK 8 also. We are facing this issue with JDK 6 also.

Did any one came across this kind of situation. I am not able to understand, just upgrading the java environment is creating this issue as there are no code changes.

Is the default date format in JDK 1.4 is different from JDK8 or 6.

Is there any way we can overcome this issue without code modifications like converting date to the required format using SimpleDateFormat etc. Below is the code we are using to convert date in to required format.

SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date d = sdf.parse(inputDate);
stmt.setDate(1, new java.sql.Date(d.getTime()));
raajaag
  • 175
  • 4
  • 18
  • Interesting issue, but without code we probably don’t stand a chance of diagnosing. There are so many places where the issue could be, so unless someone has solved the exact same problem — and even in that case — we’re left to guesswork. – Ole V.V. Mar 14 '19 at 06:14
  • Oracle database defines two (2) date/time data-types, DATE and TIMESTAMP. Both of them contain a date and a time. So I don't understand what you mean by _only date (dd-mm-yyyy)_. – Abra Mar 14 '19 at 06:40
  • 2
    There never was a “JDK 4”. There was a jdk1.4 which was branded as “Java 2”. – Holger Mar 14 '19 at 07:49

2 Answers2

2

We have faced the same issue, but when we looked in the code, we found that we have used java.sql.Timestamp.

We changed to java.sql.Date as Return type in Java. Also, in the ORACLE Database, the data type is called DATE.

Check For the return type in Java and if it remains unsolved, please update

Stefan Zobel
  • 3,182
  • 7
  • 28
  • 38
  • Both of those classes, `Timestamp` and `Date`, are terrible and are now [legacy](https://en.wikipedia.org/wiki/Legacy_system). Riddled with design flaws and hacks. They were both supplanted years ago by the *java.time* classes. Use `OffsetDateTime` instead in JDBC 4.2 or later. `OffsetDateTime odt = myResultSet.getObject( … , OffsetDateTime.class );` and `myPreparedStatement.setObject( … , odt ) ;` – Basil Bourque Mar 18 '19 at 00:26
0

if you are using start date and end date you can simply use in dao layer to get data from database

date_trunc('day',fileUploadDate) between to_timestamp(:startDate, 'dd/MM/YYYY HH:mm:ss.S') and to_timestamp(:endDate, 'dd/MM/YYYY HH:mm:ss.S')

and in controller use

SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy",Locale.ENGLISH);
Zubair
  • 31
  • 1
  • 9
  • Thanks for wanting to contribute. Please don’t teach the young ones to use the notoriously troublesome and long outdated `SimpleDateFormat` class. The asker has just upgraded to Java 8, so there is no reason whatsoever not to enjoy [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) and its `DateTimeFormatter` instead. – Ole V.V. Mar 14 '19 at 06:29
  • 1
    I am not teaching you dear.I thought that might be helpful for you,i have given my point of view ,because no one in this world is perfect.But i know one thing very well “Many people are educated but not totally mannered.” – Zubair Mar 14 '19 at 06:43