Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Urgent Help... SimpleDateFormat working differently in windows and unix.

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI!
I'm having a peculiar problem. I'm taking date as an input from a JSP and converting it into Oracle Date Format(dd-MMM-yyyy) using the following code.
I'm using this date in the where clause of a query.
Now if I run this on windows it's working perfect. It converts date into 21-Apr-2003 as required by Oracle. But if I run it on unix, the is not converting in dd-MMM-yyyy. It gives 21-04-2003. I don't understand why same code is working differently.
Can anybody help. It's very urgent.

String exceptionDate = "21/4/2003";
try{
date = DateFormat.getDateInstance( DateFormat.SHORT ).parse( exceptionDate ) ;
}catch( ParseException pe ) {
throw pe ;
}
try{
exceptionDate = new SimpleDateFormat( "dd-MMM-yyyy" ).format( date ) ;
}catch( Exception e ) {
throw e ;
}
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran into a similar date problem when I ran a java application developed in 1.3 but run under a 1.4 Windows JVM. Not sure that helps but you might want to check the JVM version.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to say, but it seems as though 21-04-2003 might be returned by some other code which you haven't shown here. Is it possible that an exception is being throws in this code, then is being caught elsewhere but not adequately logged (so you don't realize it occurred), and then some other output is generated which includes the 21-04-2003? I suggest you insert
pe.printStackTrace();
into the catch blocks, to see if this is the case.
The format represented by DateFormat.SHORT could be different from machine to machine - very possibly your Unix box uses a slightly different format. If you want a format which is the same on any machine, use SimpleDateFormat to define the format precisely rather than using DateFormat.SHORT and the like. My guess is that this is causing an exception to be thrown.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,


converting it into Oracle Date Format(dd-MMM-yyyy)


You may have made a mistake here, because as far as I know, there is no such format in Oracle. I usually use 'MM' to display the month number, or 'MON' to display the three-letter abbreviation of the month name.
In any case, according to the code you have posted, you seem to be converting a "String" to a "Date" and then converting the "Date" back to a "String". Allow me to suggest (assuming you are still unaware of it) that you use the escape syntax as defined in the JDBC specification.
(I am assuming you intend to use this date in order to query the [Oracle] database.)
More details regarding escape syntax can be found here:
http://java.sun.com/j2se/1.4.1/docs/guide/jdbc/getstart/statement.html#999472
So, for example, you can do something like:
{d,'2003-04-21'}
I have successfully used this with Oracle 8.1.7.4 and Oracle's [thin] JDBC driver and J2SE versions 1.3 and 1.4
By the way,


It converts date into 21-Apr-2003 as required by Oracle


Oracle does not have a "required" date format. Oracle has a "default" date format -- which is configurable, so it is probably different on Windows than on UNIX, which probably explains the behaviour you are seeing.
Of-course, everything about Oracle date formatting is explained in the Oracle documentation, and the documentation is available from here:
http://tahiti.oracle.com
Hope this has helped you.
Good Luck,
Avi.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As an alternative to SQL escape syntax, use PreparedStatement and set your date as SQL statement parameters.
Both in Oracle and in the JVM, the date format is configurable and locale-specific. The difference you're seeing between Unix and Windows may simply be a locale configuration issue. My advice generally would be to make no assumptions whatsoever about the specific date format used either by Oracle or by the JVM (except, obviously, when parsing user input) -- i.e. use escapes or PreparedStatement throughout.
- Peter
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic