1

I am facing a problem where even though dates are stored in Oracle Database in default date format i.e dd-Mon-yy (for example 28-MAR-11) ,the date columns are automatically formatted into yyyy-MM-dd (for example 2011-03-28) while connecting to Oracle database from java using Oracle JDBC driver.Looked into the documentation but could not find any setting change that would effect the default date format. I want to resolve this problem by making the configuration changes instead of formatting the dates in java.Please let me know if there is a solution. Note:I am using spring JDBC.

tyagi
  • 265
  • 2
  • 10
  • The dates in your example are the same, I would guess it is merely formatting that is puzzling you - what date formatting are you using for your output? – Guy Flavell Sep 16 '14 at 10:04
  • 3
    Dates in Oracle do not have, and are not stored with, any format. They have an internal representation which isn't really relevant here. Whichever client you use formats the dates for display based on the client and session settings (NLS_DATE_FORMAT if you don't specify a format). Java is retrieving the date as a date, not a string. If you need it in a particular format for display in your application, you'll have to format it in Java after retrieval, e.g. [with SimpleDateFormat](http://stackoverflow.com/a/5683747/266304). – Alex Poole Sep 16 '14 at 10:05

1 Answers1

0

Change the DATE TIME FORMAT in Query itself (instead of using date-time formatter in Java)which you are using to retrieve date.I had the same Issue when working with one of my spring MVC project.I hope this helps.

For Example:

SELECT ProductName, Price, FORMAT(Now(),'YYYY-MM-DD') AS PerDate
FROM Products;
Lokesh
  • 313
  • 2
  • 12