Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: NLS_DATE_FORMAT in jdbc

Re: NLS_DATE_FORMAT in jdbc

From: Laurenz Albe <invite_at_spam.to.invalid>
Date: 31 May 2007 09:45:53 GMT
Message-ID: <1180604749.495148@proxy.dienste.wien.at>


CM Wong <cmwong2_at_yahoo.com> wrote:

>>> I've seen many discussion on setting NLS_DATE_FORMAT. But when I tried
>>> to set NLS_DATE_FORMAT inside jdbc, it didn't seem to have any effect.
>>> Please see my codes below. Anyone has an idea?
>>
>> That's hardly surprising.
>> What you get with rs.getObject(1) is an instance of java.sql.Date, which
>> then is converted to a java.lang.String using its toString() method.
>>
>> Change the SQL statement to
>>
>> SELECT to_char(trade_date) FROM indx
>>
>> because then Oracle and not Java converts the date to a string.

>
> Thanks for your reply. I'm surprise to see that the output from
> getString(1) is different from getObject(1), but it's still not the
> date format I want in the "alter session" statement. Unfortunately, I
> can't use to_char() because I don't know the column name in advance.
> In fact, in my production code running in tomcat, it simply returns
> all the columns to the web browser, which then display the needed
> columns selected by the user.

getObject() of course returns something different from getString() if you have a DATE column - a java.sql.Date is not a java.lang.String.

Since formatting a java.sql.Date is not Oracle's problem, you'll have to find the solution in Java or Tomcat.

In Java, you normally use something like java.text.DateFormat. Maybe you can teach Tomcat to format dates in a certain way - ask a Tomcat group!

Yours,
Laurenz Albe Received on Thu May 31 2007 - 04:45:53 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US