aspose file tools*
The moose likes JDBC and the fly likes Convert a String with a date valus for Oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Convert a String with a date valus for Oracle" Watch "Convert a String with a date valus for Oracle" New topic
Author

Convert a String with a date valus for Oracle

Reggie McDougal
Ranch Hand

Joined: Sep 27, 2004
Posts: 69
How do I take a date entered into a text field and add it to the database as a date format so I can query it.

e.g. (European) 12/01/2005

what API's are available for Oracle to format from a String to a proper date format?

If some one has code example.

Reg


You can never drink too much
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1132

Reggie,
As requested. Note, however, that the below code is uncompiled, and untested.
It is also not really complete. It is intended only as a guide -- to get you started (with your homework assignment?)

Good Luck,
Avi.
Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
Using the jdbc interface all you need to pass is the java object for date or timestamp whichever is applicable. If you are passing a string to an oracle procedure or function that depends on the NLS_DATE_FORMAT database parameter. This can be modified for a session using the ALTER SESSION command.


Jeremy Wilson
Reggie McDougal
Ranch Hand

Joined: Sep 27, 2004
Posts: 69
Thanks, thanks what I needed to know

Reg
Reggie McDougal
Ranch Hand

Joined: Sep 27, 2004
Posts: 69
This works fine, rather than use the API the oracle format is simpler
is there any disadvantage to this method?

Reg



[edited to add line breaks so page doesn't scroll right]
[ January 19, 2005: Message edited by: Jeanne Boyarsky ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes. By parsing your date string in SQL, you tie your JDBC code to Oracle, rather than leaving it database independant as it would be if you parsed the date in your Java code. Also you tie your date parsing to one Locale. By convention dates are described differently depending on where you are in the world (for example, typically Americans put the month before the day, while the British put the day before the month). If you parse your date in Java you can swap the formatting rules depending on Locale, but you can't do this in SQL.
[ January 19, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
 
subject: Convert a String with a date valus for Oracle