Skip to content
Advertisement

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

I am getting the following error when inserting data into my oracle database.

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

In database date is as: dd-MMM-yy (06-MAR-12)
I am converting 06-03-2012 to dd-MMM-yy by the following method:

String s="06-03-2012";

String finalexampledt = new SimpleDateFormat("dd-MMM-yy").format(new SimpleDateFormat("dd-MM-yyyy").parse(s));

So i got 06-Mar-12 which is same as the above database date format still i am getting the error. I am inserting as:

in index.jsp

 String todaydate="";

Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
todaydate = dateFormat.format(calendar1.getTime());

<input type="text" name="datename" value="<%=todaydate%>"/>

in servlet(doPost)

String s=request.getParameter("datename");

PreparedStatement ps=con.prepareStatement("insert into tablename(rest_dt, othercolname) values (to_date(?, 'dd-mm-yyyy'), ?)");

ps.setString(1, s);
ps.setString(2, otherstringdata);

int  rs=ps.executeUpdate();

Any idea please

Advertisement

Answer

so make

("insert into mytablename (rest_dt) values to_date(?, 'DD-MM-YYYY')");  

Try this

TO_DATE(?, 'DD-MM-YYYY','NLS_DATE_LANGUAGE = American')  

// gets from Oracle docs

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement