严重: Servlet.service() for servlet action threw exception 请问这个错误该怎么改,百思不得其解,谢谢
java.lang.IllegalArgumentException:Timestampformatmustbeyyyy-mm-ddhh:mm:ss[.fffffffff...
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
at java.sql.Timestamp.valueOf(Timestamp.java:194)
at com.personaloffice.workplan.ImpDaoCalendar.getRemindCalendar(ImpDaoCalendar.java:193)
at com.struts.action.workplan.RemindCalendarAction.execute(RemindCalendarAction.java:35)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
以下是源代码:
public String getRemindCalendar(Integer empid) {
GregorianCalendar gcal=new GregorianCalendar(); //获得当前时间
DateFormat df = DateFormat.getDateTimeInstance(); //设定格式yyyy-mm-dd hh:mm:ss
Date date=gcal.getTime(); //将当前时间转成日期对象
String datetime=df.format(date); //获得符合格式的字符串,当前日期时间
int index=datetime.indexOf(" ");
String selectday=datetime.substring(0,index); //当前日期
Timestamp nowdatetime = Timestamp.valueOf(datetime); //将当前日期换成Timestamp对象
Session se=HibernateSessionFactory.currentSession();
Employee emp=(Employee)se.get(Employee.class,empid);
StringBuffer xml = new StringBuffer();
List list=null;
try{
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
xml.append("<calendars>\n");
Query query=se.createQuery("from Calendar as c where c.employee=:emp and c.calendarIsremid=1 and c.calendarEndtime>=:nowdatetime");
query.setEntity("emp",emp);
query.setTimestamp("nowdatetime",nowdatetime);
list=query.list();
for(int i=0;i<list.size();i++){
Calendar cal=(Calendar)list.get(i);
gcal.add(GregorianCalendar.MINUTE,cal.getCalendarRemind().intValue()); Date remindtime=gcal.getTime(); String strnewstart=df.format(cal.getCalendarStarttime()); Date newstart=df.parse(strnewstart);
if(newstart.before(remindtime)){
xml.append("\t<calendar>\n");
xml.append("\t\t<title>");
xml.append("日程提醒:" + cal.getCalendarTitle()+"");
xml.append("</title>\n");
xml.append("\t\t<date>");
xml.append(selectday);
xml.append("</date>\n");
xml.append("\t\t<content>");
// xml.append(strnewstart + ",您有一个日程 " + cal.getCalendarContent()+"");
// xml.append("您有一个日程:" + cal.getCalendarContent() + "");
xml.append(strnewstart+","+cal.getCalendarContent());
xml.append("</content>\n");
xml.append("\t\t<id>");
xml.append(cal.getCalendarId());
xml.append("</id>\n");
xml.append("\t</calendar>\n");
}
}
xml.append("</calendars>");
return xml.toString();
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
HibernateSessionFactory.closeSession();
}
} 展开
at java.sql.Timestamp.valueOf(Timestamp.java:194)
at com.personaloffice.workplan.ImpDaoCalendar.getRemindCalendar(ImpDaoCalendar.java:193)
at com.struts.action.workplan.RemindCalendarAction.execute(RemindCalendarAction.java:35)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
以下是源代码:
public String getRemindCalendar(Integer empid) {
GregorianCalendar gcal=new GregorianCalendar(); //获得当前时间
DateFormat df = DateFormat.getDateTimeInstance(); //设定格式yyyy-mm-dd hh:mm:ss
Date date=gcal.getTime(); //将当前时间转成日期对象
String datetime=df.format(date); //获得符合格式的字符串,当前日期时间
int index=datetime.indexOf(" ");
String selectday=datetime.substring(0,index); //当前日期
Timestamp nowdatetime = Timestamp.valueOf(datetime); //将当前日期换成Timestamp对象
Session se=HibernateSessionFactory.currentSession();
Employee emp=(Employee)se.get(Employee.class,empid);
StringBuffer xml = new StringBuffer();
List list=null;
try{
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
xml.append("<calendars>\n");
Query query=se.createQuery("from Calendar as c where c.employee=:emp and c.calendarIsremid=1 and c.calendarEndtime>=:nowdatetime");
query.setEntity("emp",emp);
query.setTimestamp("nowdatetime",nowdatetime);
list=query.list();
for(int i=0;i<list.size();i++){
Calendar cal=(Calendar)list.get(i);
gcal.add(GregorianCalendar.MINUTE,cal.getCalendarRemind().intValue()); Date remindtime=gcal.getTime(); String strnewstart=df.format(cal.getCalendarStarttime()); Date newstart=df.parse(strnewstart);
if(newstart.before(remindtime)){
xml.append("\t<calendar>\n");
xml.append("\t\t<title>");
xml.append("日程提醒:" + cal.getCalendarTitle()+"");
xml.append("</title>\n");
xml.append("\t\t<date>");
xml.append(selectday);
xml.append("</date>\n");
xml.append("\t\t<content>");
// xml.append(strnewstart + ",您有一个日程 " + cal.getCalendarContent()+"");
// xml.append("您有一个日程:" + cal.getCalendarContent() + "");
xml.append(strnewstart+","+cal.getCalendarContent());
xml.append("</content>\n");
xml.append("\t\t<id>");
xml.append(cal.getCalendarId());
xml.append("</id>\n");
xml.append("\t</calendar>\n");
}
}
xml.append("</calendars>");
return xml.toString();
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
HibernateSessionFactory.closeSession();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询