Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert a String with a date valus for Oracle

 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, thanks what I needed to know

Reg
 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic