Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6785 times.
Similar Threads
Passing date and time using Timestamp.
Date Conversion in SQL
parsing in servlet
java.sql.Timestamp to Oracle date
SQL to retrieve date vals from ORA-DB
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:04:41.