Monday, December 29, 2008

Problem with date format in JDBC session

The other day I came across this issue and spent some time figuring out what was going on. Hope it can help someone.

Issue:
Say there’s a stored procedure in Oracle named test_date which uses a variable of type DATE. The variable is not returned to java but simply used elsewhere in the procedure.
If I execute this procedure in oracle and check the date format, I see it’s using the format dd-mon-yyyy

If I execute this procedure over jdbc, the format I see is mm-dd-yyyy

This makes me believe that the date format used throughout the session is defined by the client (oracle vs. jdbc).

Fix:
Simple way to fix this is to alter the session at runtime and explicitly define the format used throughout the session
alter session set nls_date_format=''DD-MON-YYYY''

No comments:

Post a Comment