-2

I am getting date in html 5 input type = "date" format..in mm/dd/yyyy format. Then I am getting it String fDate = request.getParameter("fromDate");

room.setFromDate(fDate);

Then while trying to run query

insert into tbl_room_under_maintenance(room_id,room_number,from_date,to_date)
values(?,?,to_date(?,'MM/DD/YYYY'),to_date(?,'MM/DD/YYYY'))

PS1.setString(3,room.getFromDate().trim());
PS1.setString(4,room.getToDate().trim());

it shows error : java.sql.SQLException: ORA-01843: not a valid month

shashin
  • 1
  • 1
  • 1
  • did you check what is the value that you get from getFromDate().trim())? – Thusitha Thilina Dayaratne Aug 03 '14 at 12:49
  • 4
    You either do *not* get the date in the format you think, or it indeed contains an invalid month. –  Aug 03 '14 at 12:49
  • 2
    add the output of printing `fDate` in the post – Pat Aug 03 '14 at 12:52
  • There's no need to add the data @Pat; as the problem is the data the only answer anyone is going to be able to give the OP is to point out the '36' (or whatever it is) is not a month.., which isn't very useful for anyone in the future. – Ben Aug 03 '14 at 13:39
  • 3
    @Ben It was precisely the reason I asked for data :) – Pat Aug 03 '14 at 13:53

1 Answers1

0

Convert the date before insert:

String fDate = request.getParameter("fromDate");
SimpleDateFormat sm = new SimpleDateFormat("mm/dd/yyyy");
Date dat = sm.parse(fDate);
insert into tbl_room_under_maintenance(room_id,room_number,from_date,to_date)
values(?,?,?,?)
PS1.setDate(3,dat);
neshkeev
  • 6,280
  • 3
  • 26
  • 47