I have the below SQL query
select to_date(start_date, 'dd-Mon-yy') AS start_date FROM table
I also have the below ResultSet objects (rs)
rs.getDate("start_date")
When I run the query in SQL developer directly against the database (Oracle) the format is returned as expected (08-AUG-12), but when I run the query in my Java app using JDBC it prints out as 2012-08-08.
Am I getting the format the correct way? Should I just select on the column (date datatype) and then format via JodaTime’s DateTimeFormatter? I’m not sure what I’m doing wrong here.
The same thing happens when I convert from java.sql.Date to java.util.Date…
Database format is not taken in consideration when you are dealing with a
Dateobject in Java. If you want to match exactly the format that you have on your function, you can useTO_CHAR, and fetch the column as aString.Alternatively, you keep fetching the column as
Date, and then format it accordingly withDateTimeFormatter, for example.