因为本地编译环境是tomcat,但需要发布到服务器weblogic环境中去。一个困扰我很久的问题,Date类日期函数在tomcat上可运行通过,但是在weblogic上运行报错,,如以下例子:
Date tmpDate = null;
if(rsPlan.getRowCount()>0){
    tmpDate = rs.getDate(0,"PLAN_TIME") // *


    SimpleDateFormat fm = new   SimpleDateFormat("yyyy-MM");
    String strTime = fm.format(tmpDate); //在weblogic上运行失败
将 * 处的代码改为
tmpDate = new java.sql.Date(rsPlan.getDate(0,"PLAN_TIME").getTime());依然
报错,报错为:
  java.lang.NullPointerException                                  at java.util.Calendar.setTime(Calendar.java(Compiled Code))                                              at java.text.SimpleDateFormat.format(SimpleDateFormat.java(Compiled Code))                                                    at java.text.SimpleDateFormat.format(SimpleDateFormat.java(Compiled Code))                                                    at java.text.DateFormat.format(DateFormat.java(Compiled Code))                                               at epm.component.ckplan.cmp_ck_cycle_plan_add.CommonProcessor.showInitPage(CommonProcessor.java:71)
                     at epm.component.ckplan.cmp_ck_cycle_plan_add.ShowHandler.handleEvent(ShowHandler.java:19)
                     at epm.component.ckplan.cmp_ck_cycle_plan_add.ShowHandler.handleEvent(ShowHandler.java:19)
                     at ep.si.Component.handleEventInner(Unknown Source)                                          at ep.si.Component.handleEvent(Unknown Source)                                        at ep.si.ComponentUtil.sendEvent(Unknown Source)                    
  ?
                     at ep.si.ComponentAction.execute(Unknown Source)                                         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java(Inlined Compiled         Code))    
哪位高手能揭示问题根源,给出解决方案,不胜感激之至。

解决方案 »

  1.   


    String strTime = fm.format(tmpDate);
    之前加一句输出看看tmpDate变量的值是否有效。
      

  2.   

    rs.getDate(0)得到是空值,所以出错.
      

  3.   

    1、查看 rsPlan.getRowCount()>0 是否成立
    2、条件1的基础上,观察rs.getDate(0,"PLAN_TIME") 是否有值取出
      

  4.   

    tmpDate = rs.getDate(0,"PLAN_TIME") 是有值的,在本机上tomcat环境下,用eclipse调试,
    每一步都不会报错,运行无误。根据程序的设置,实际上getDate(0,"PLAN_TIME")是不可能得到空值的。据说是weblogic和tomcat对oracle日期函数的编译是不一样的,谁知道这方面的信息吗?