Nissan Vietnam
Nissan Vietnam

Reputation: 31

Oracle NLS_DATE_FORMAT using Eclipse

I have problem with NLS_DATE_FORMAT.

I was run this:

ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24: MI: SS';
ALTER SESSION SET NLS_TIME_FORMAT = 'HH24: MI: SSXFF';
ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24: MI: SSXFF';

On server show sysdate => 2016-01-18 => OK

But when I run SQL script from java, It always show 18-FEB-16. How to change to 2016-01-18 without edit my source code.?

Upvotes: 0

Views: 1488

Answers (1)

Felipe Moreno
Felipe Moreno

Reputation: 508

I don't know about the JAVA specific configuration, but you could create an after logon trigger at DB to alter the NLS configuration:

How to change default nls_date_format for oracle jdbc client

CREATE OR REPLACE TRIGGER LOGINTRG
AFTER LOGON ON DATABASE
BEGIN
   if user = 'MYUSER' then -- if you can do that better
   EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''';
   end if;
END LOGINTRG;

I would suggest adding a if statement to just do that when the connected user is the one your application uses.

Upvotes: 1

Related Questions