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

梦想与她 提交于 2019-12-13 08:07:39

问题


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


回答1:


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);


来源:https://stackoverflow.com/questions/25104784/java-sql-sqlexception-ora-01843-not-a-valid-month-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!