user1635967
user1635967

Reputation: 39

how to get date value in jsp and update it to mysql

I have to insert date dynamically to database, how should I get the text value and update it ? I have tried the following code.

<input type="Text" name="tbox" id="${up.adId}" maxlength="15"size="18" value="${expiryDate}"><a href="javascript:NewCal(${up.adId},'mmddyyyy',false,24)"> 

UPDATE classifiedads SET expiry_date='"+ textBox[i]+"' where

in where what condition should be checked from the above code.

i want to save edited values in textbox to the database remaining untouched but as i am giving value of each textbox as expiry date initially , i am unable to write where condition for edited values please help me i am strucked .

if i update with out where condition null values are updated

thanks in advance.

Upvotes: 0

Views: 1917

Answers (2)

satyam.kudikala
satyam.kudikala

Reputation: 99

You can solve this problem by changing the query with to_date(<value-to-insert>,'<format>')

Ex: select to_date('2007-01-01 12:00:01 AM','yyyy-mm-dd hh:mi:ss pm') as dt from dual;

in your case :

UPDATE classifiedads SET expiry_date=to_date('"+ textBox[i]+"','mmddyyyy') where " e.t.c

Let me know in case of any issues.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240860

On servlet you would receive date in the form of String, you need to do following steps to get Date from this string date

  • Validate String date for nullity and format
  • Convert from String Date to Date instance using SimpleDateFormat

Upvotes: 1

Related Questions