I’m currently using the Spring framework, though I’m not sure if this is directly the issue. I’m getting the following error:
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);
}
What I have is a search form that queries the DB and returns results into a table. I’m pulling data from Oracle DB table where the column type is Date but for some reason it’s telling me that it cannot cast from a Timestamp value. I’m not requesting a Timestamp value at all.
Any help is greatly appreciated.
It appears that one or all of COLL_OPEN_DT, COLL_CLOSE_DT, and COLL_AVLBL_DT is a timestamp in the database. Luckily
java.sql.Timestampextendsjava.util.Date.Option 1
Change the date elements in the
CollectionCalendarclass to be java.util.DateOption 2
Create a class with a mehod that takes a java.sql.Timestamp
and returns ajava.sql.Date`Here is a simple example:
Then change the code above to something like this:
Option 3
Something else (that I did not think of).