• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

inserting a string containing date into oracle table which has the date type field

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have a html page which accepts the date from text box in dd/mm/yyyy format.
this date string is stored in string variable in next jsp page.
now how can i store this string variable into oracle table which has coloumn with date data type.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suchita,
Welcome to JavaRanch!

Take a look at the SimpleDateFormat class. This converts your String into a Date. Then you can use stmt.setDate() and let Oracle worry about the database format.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suchita ,

You can do it in either way either convery string into Date typoe in Java Code or Do it in Oracle.

To do same in oracle,simply you can use to_date function of oracle to covert your string into date type

Syntax is to_date(String,Format)

if you want to insert a date ie 06/12/2004 in dd/mm/yyyy format,
You can do same like this

insert into table_name(Date_column) values(to_date('06/12/2004','dd/mm/yyyy'))

thanks
[ December 06, 2004: Message edited by: Shailesh Chandra ]
 
Skool. Stay in. Smartness. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic