This discussion is archived
1 Reply Latest reply: Aug 16, 2012 9:47 AM by rp0428 RSS

How to change session using JDBC

user11995226 Newbie
Currently Being Moderated
Hi,
I want to change oracle session (alter session set NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS am') using jdbc.

The stmt.execute( "alter session set NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS am'" ) executed successfully but date format dose not change.

Is there anyway i can alter session on the fly ?


My Environment.
Oracle 11g
Windows 7 64 bit.


Thanks
With Regards
  • 1. Re: How to change session using JDBC
    rp0428 Guru
    Currently Being Moderated
    >
    The stmt.execute( "alter session set NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS am'" ) executed successfully but date format dose not change.

    Is there anyway i can alter session on the fly ?
    >
    You just did alter it.

    Saying 'data format dose not change' has no meaning. What test did you do to see if the date format changed?

    See this example of changing the date format and then testing that it changed from the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_2012.htm
    Changing the Date Format Dynamically: Example The following statement dynamically changes the default date format for your session to 'YYYY MM DD-HH24:MI:SS':
    ALTER SESSION 
       SET NLS_DATE_FORMAT = 'YYYY MM DD HH24:MI:SS';
    Oracle Database uses the new default date format:
    SELECT TO_CHAR(SYSDATE) Today
       FROM DUAL; 
    
    TODAY 
    ------------------- 
    2001 04 12 12:30:38
    See the last line? The TO_CHAR function used the NSL_DATE_FORMAT to format the date.

    You do realize, I hope, that the ALTER SESSION changes the value that Oracle uses, not the value that your Java code may use.

    Post the code for the test you did and what you are trying to do.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points