How to use "alter session ..." with Oracle JDBC.
1 posts in topic
Flat View  Flat View

Posted By:   Thanks_forHelp
Posted On:   Wednesday, November 19, 2008 02:49 AM

I tried:

stmt.execute("alter session set nls_date_format='yyyymmdd'");

It executes correctly, yet it doesn't seem to have any effect on the date format in the following result set:

Resultset rs = stmt.executeQuery(sql);

The data is always formatted as yyyy-mm-dd.

Any advice is greatly appreciated.

Re: How to use "alter session ..." with Oracle JDBC.

Posted By:   Lance_Callaway  
Posted On:   Thursday, January 8, 2009 06:11 PM

I had the same question and came across your post ... I later found an answer (it worked for me anyway).

In short (from what I now psuedo understand) - this will not ever work. Java sidesteps the Oracle formatting when it retrieves the data.

There is a work around. If you do a:
select to_char(field_name) from ....

Then Oracle will use the session data you set to format the string before Java ever accesses it.

Hope that helps.
About | Sitemap | Contact