java.sql.SQLException:ORA-01843:不是有效的一个月 [英] java.sql.SQLException: ORA-01843: not a valid month

查看:515
本文介绍了java.sql.SQLException:ORA-01843:不是有效的一个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  java.sql.SQLException:ORA-01843在我的oracle数据库中插入数据时,我收到以下错误:不是有效月份

数据库日期为:dd-MMM-yy(06-MAR- 12)

我通过以下方法将06-03-2012转换为dd-MMM-yy:

  String s =06-03-2012; 

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

所以我有06-Mar-12与上述数据库日期格式相同,我还得到错误。我在index.jsp中插入:





  String todaydate =; 

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

< input type =textname =datenamevalue =<%= todaydate%>/>

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

任何想法请

解决方案

所以make

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

尝试这个

 code> TO_DATE(?,DD-MM-YYYY,NLS_DATE_LANGUAGE =美国)

//从 Oracle文档获得


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

解决方案

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

这篇关于java.sql.SQLException:ORA-01843:不是有效的一个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆