Re: NLS_DATE_FORMAT in jdbc



On 5月30日, 下午2時54分, Laurenz Albe <inv...@xxxxxxxxxxxxxxxx> wrote:
CM Wong <cmwo...@xxxxxxxxx> 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?

[...]
Statement stat=conn.createStatement();

stat.execute("alter session set NLS_DATE_FORMAT='YYYY-DD-
MM HH24:MI:SS'");

ResultSet rs=stat.executeQuery("select trade_date from
indx");
while (rs.next())
System.out.println(rs.getObject(1)); // *** new
format not effective here ***

[...]

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.

And java.sql.Date.toString() certainly won't depend on a previous
ALTER SESSION SQL statement.

Try to use rs.getString(1) instead and see if it makes a difference!

I'm too lazy to try if that will work (probably not), but here's what
will certainly work:

Change the SQL statement to

SELECT to_char(trade_date) FROM indx

because then Oracle and not Java converts the date to a string.

Yours,
Laurenz Albe- 隱藏被引用文字 -

- 顯示被引用文字 -

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.

Regards,
CM

.



Relevant Pages

  • Re: changing text color
    ... ; undefined variable: princ ... ((equalp "Green" color) ... mixed in with the format statement and no arguments are ... supplied for the control codes. ...
    (comp.lang.lisp)
  • Re: Switches/field codes to fix zip code in merge
    ... It doesn't work in all cases (e.g. if you do not actually have Excel ... If you enter 5-digit ZIPs by entering the 5 digits, ... have ZIP codes with leading zeroes, you can ensure that you always ... see all 5 digits by applying the ZIP format, ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Date value filtering out 0 in day!!
    ... reserved word, and using reserved words can lead to all sorts of problems. ... My regional settings was set to m/d/yyyy> so fixing that should fix the problem. ... >> Unless you apply an explicit format, Access gets its date format from the>> Regional Settings. ... I don't understand why that would prevent you from returning any>> values in your SQL statement. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Switches/field codes to fix zip code in merge
    ... switching to the DDE approach that Graham has mentioned will sort out a lot of problems using Excel data sources. ... If you enter 5-digit ZIPs by entering the 5 digits, Excel will save the data as a number with "General" formatting and display the number, right justified, with no leading zeroes. ... If it is possible to have ZIP codes with leading zeroes, you can ensure that you always see all 5 digits by applying the ZIP format, which is a numeric format: ...
    (microsoft.public.word.mailmerge.fields)
  • Re: "MR2"
    ... Those codes are processor codes / conversions. ... A format mask as ... historically Pick has allowed numeric conversion codes w/ or w/o format ... guessing that's the result of a failed date conversion. ...
    (comp.databases.pick)