Re: NLS_DATE_FORMAT in jdbc



CM Wong <cmwong2@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
.



Relevant Pages

  • Re: NLS_DATE_FORMAT in jdbc
    ... Please see my codes below. ... ALTER SESSION SQL statement. ... date format I want in the "alter session" statement. ...
    (comp.databases.oracle.misc)
  • Re: Splitting databases
    ... Set rs = db.OpenRecordset (strSQL) ... Or perhaps even simpler is just execute an SQL statement ... if the user decides to cancel the operation the code returns ... to the Codes table and subtracts 1 from the existing number. ...
    (microsoft.public.access.gettingstarted)
  • Re: Meta data of query?
    ... Would it be easier to parse the SQL statement. ... where is the meta-data of a result set of a stored procedure ... Column meta data is not persisted for ad-hoc queries and SQL statement ... Although you can get resultset meta data directly in Transact-SQL, ...
    (microsoft.public.sqlserver.programming)
  • OK
    ... I use the following codes to delete a records from dbgrid: ... You should not call both the ExecSQL and the Open methods. ... Open for any SQL statement except SELECT. ...
    (borland.public.delphi.database.ado)
  • Re: Using "Not" in criteria
    ... Are you using the ALL universal qualifier? ... SQL statement with us? ... > I am searching for records that might have a range of codes in any of 10 ... Is there an explanation for this? ...
    (microsoft.public.access.queries)