0

我目前正在使用 Spring 框架,但我不确定这是否是直接的问题。我收到以下错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.sql.Date org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:929) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:824) javax.servlet.http.HttpServlet.service(HttpServlet.java:641) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:798) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    @SuppressWarnings({ "rawtypes", "unchecked"})
public List getAllByFilter( String collectionPeriod,String sYear, String submission) {
    // TODO Auto-generated method stub SELECT_QUERY_BY_COLL_MSTR

    List<CollectionCalendar> orgs1 = new ArrayList<CollectionCalendar>();        
    List<Map<String,Object>> rows1 = null;
    String query="SELECT_QUERY_BY_COLL_MSTR";

    if("All".equalsIgnoreCase(sYear) && "All".equalsIgnoreCase(collectionPeriod)){
        query="SELECT_QUERY_BY_COLL_MSTR_SUBMISSION";
         rows1 = getJdbcTemplate().queryForList(p.getProperty(query),new Object[] {submission});
    }else if(!"All".equalsIgnoreCase(sYear) && "All".equalsIgnoreCase(collectionPeriod)){
        query="SELECT_QUERY_BY_COLL_MSTR_SUBMISSION_YEAR";
         rows1 = getJdbcTemplate().queryForList(p.getProperty(query),new Object[] {sYear,submission});
    }else if("All".equalsIgnoreCase(sYear) && !"All".equalsIgnoreCase(collectionPeriod)){
        query="SELECT_QUERY_BY_COLL_MSTR_SUBMISSION_COLLECTION";
         rows1 = getJdbcTemplate().queryForList(p.getProperty(query),new Object[] {collectionPeriod,submission});
    }else if(!"All".equalsIgnoreCase(sYear) && !"All".equalsIgnoreCase(collectionPeriod)){      
         rows1 = getJdbcTemplate().queryForList(p.getProperty(query),new Object[] {sYear,collectionPeriod,submission});
    }
    System.out.println("hellooooooooooooooooooo");
    for (Map row : rows1) {
        System.out.println("row------"+row);
        CollectionCalendar collectionCalendar = new CollectionCalendar(row.get("COLL_KEY").toString(),
                (Date)row.get("COLL_OPEN_DT"),
                (Date)row.get("COLL_CLOSE_DT"),
                (Date)row.get("COLL_AVLBL_DT"),
                row.get("COLL_ACAD_YR").toString(),
                row.get("COLL_NAME").toString(),
                row.get("COLL_DESC").toString(),
                row.get("SUBM_DESC").toString(),
                row.get("UPDATE_USER").toString());
                //(Timestamp) row.get("UPDATE_DTTM"));            
        orgs1.add(collectionCalendar); (COMMENTED THIS OUT BUT STILL GETTING ERROR)
    }
    return orgs1;
}

public CollectionCalendar(String colKey,Date opDate,Date clDate,Date avDate,String sYear,String submission,String collectionPeriod,String subDesc,String updateUser){
    setCollKey(colKey);
    setOpenDate(opDate);
    setCloseDate(clDate);
    setAvailDate(avDate);
    setsYear(sYear);
    setSubmission(submission);
    setCollectionPeriod(collectionPeriod);
    setSubDesc(subDesc);
    setUpdateUser(updateUser);
    //setUpdateTime(updateTime);
}

我拥有的是一个查询数据库并将结果返回到表中的搜索表单。我正在从列类型所在的 Oracle DB 表中提取数据,Date但由于某种原因,它告诉我它不能从Timestamp值中转换。我根本不要求Timestamp价值。

任何帮助是极大的赞赏。

4

1 回答 1

3

看起来 COLL_OPEN_DT、COLL_CLOSE_DT 和 COLL_AVLBL_DT 中的一个或全部是数据库中的时间戳。幸运java.sql.Timestamp地延伸java.util.Date

选项1

将类中的日期元素更改CollectionCalendar为 java.util.Date

选项 2

使用采用 java.sql.Timestamp and returns ajava.sql.Date`的方法创建一个类

这是一个简单的例子:

class Blammy
{
  static final java.sql.Date convertTimestamp(final java.sql.Timestamp timestamp)
  {
    java.sql.Date returnValue;

    if (timestamp != null)
    {
      returnValue = new java.sql.Date(timestamp.getTime());
    }
    else
    {
      returnValue = null; // an exception might be better here.
    }

    return returnValue
  }
}

然后把上面的代码改成这样:

...
Blammy.convertTimestamp(row.get("COLL_OPEN_DT")),
...

选项 3

别的东西(我没想到)。

于 2013-01-28T18:09:03.370 回答