Excel文件有字段为("2010-07-06")。在读取的过程中已经进行转换
DateFormat format= new SimpleDateFormat("yyyy-MM-dd");
accept.setComplainDate(format.parse(sheet.getCell(1,i).getContents()));//读取("2010-07-06")。
虽能导入到数据库,但是后台还是有报错如下:
2010-07-06 17:55:14,421 [http-8080-Processor25] ERROR [500.jsp] - Unparseable date: ""
java.text.ParseException: Unparseable date: ""
at java.text.DateFormat.parse(DateFormat.java:335)
at com.foomei.wjcg.web.action.AcceptRegistrationAction.importexcel(AcceptRegistrationAction.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
DateFormat format= new SimpleDateFormat("yyyy-MM-dd");
accept.setComplainDate(format.parse(sheet.getCell(1,i).getContents()));//读取("2010-07-06")。
虽能导入到数据库,但是后台还是有报错如下:
2010-07-06 17:55:14,421 [http-8080-Processor25] ERROR [500.jsp] - Unparseable date: ""
java.text.ParseException: Unparseable date: ""
at java.text.DateFormat.parse(DateFormat.java:335)
at com.foomei.wjcg.web.action.AcceptRegistrationAction.importexcel(AcceptRegistrationAction.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
解决方案 »
- 我们爱分享---Obey the general contract when overriding equals
- 将CSDN首页添加到您的开始菜单,实现快速访问其实是骗点击的,是广告
- Log4j 比较简单的问题
- 判断一个复选框是否被选中???
- spring中如何根据时间调用方法
- 关于spring的一点问题,请高手帮忙解决
- 谁有strut的学习的电子书啊?(有分相赠 ^_^ )
- jsp中OUT.PRINT后加HTML出现的问题
- 请问那里有java类库的电子书籍下载和图书出售
- Service层到底该怎么写才是符合j2ee的标准的?
- hibernate或者ibatis能否持久化至XML 或者SRPING事务能否对文件修改进行回滚
- 用Struts2标签创建表单的问题
accept.setComplainDate(java.sql.Date.valueOf(format.format(sheet.getCell(1,i).getContents())));//读取("2010-07-06")。
if(CellType.DATE.equals(cells[0].getType())){
DateCell dateCell = (DateCell) cells[0];
DateFormat format= new SimpleDateFormat("yyyy-MM-dd");
accept.setComplainDate(format.parse(dateCell.getDate()));
}
这样就可以了
举例子:CellType t1 = cell.getType();
Date regDate = null;
if (t1 == CellType.DATE)
{
DateCell regCell = (DateCell) cell;
regDate = regCell.getDate();
}
else if (t1 == CellType.EMPTY)
{
regDate = null;
}
else
{
SimpleDateFormat sdf = new SimpleDateFormat(("yyyy-MM-dd");
try
{
regDate = sdf.parse(value);
} catch (ParseException pe) {
}
}
数据库的data类型 和java里面的 data类型不一致的。
数据库是 java.sql.Date Java里面是 java.util.Date 所以一般是先把java里面的date类型转换为String类型 然后在插入数据库的时候用java.sql.Date.valueOf()***;