Java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp


HOME » Java

I have a jrxml file. When I run that file in IReport Designer 4.8.0, Produces report without fail.
But when I deploy the same file in JasperServer 5.0.0, it throws exception.


The server has encountered an error. Please excuse the inconvenience.
Error Message
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
Error Trace
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.setTimestamp(JRJdbcQueryExecuter.java:605) at
net.sf.jasperreports.engine.query.JRJdbcQue

Related to : Java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
Java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
Java

I have a jrxml file. When I run that file in IReport Designer 4.8.0, Produces report without fail.
But when I deploy the same file in JasperServer 5.0.0, it throws exception.


The server has encountered an error. Please excuse the inconvenience.
Error Message
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
Error Trace
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.setTimestamp(JRJdbcQueryExecuter.java:605) at
net.sf.jasperreports.engine.query.JRJdbcQue
Gradle - Execution failed for task 'sonarAnalyze' - java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String
Java

I have this error when running sonar with my gradle build script.


gradle sonarAnalyze


15:41:02.931 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:41:02.931 [ERROR] [org.gradle.BuildExceptionReporter]
15:41:02.931 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:41:02.931 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':sonarAnalyze'.
15:41:02.934 [ERROR] [org.gradle.BuildExceptionReporter] > java.util.ArrayList cannot be cast to java.lang.String
My sonar
sonar {
server {

Retrieving SQL enum causes java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
Java

I have a query like this


Query importQuery = advertiserDao.getEntityManager().createNativeQuery(
"select matching_type from group_key where key_id = " + Key.getkeyId());
String match = (String) importQuery.getSingleResult();

The matching_type is a enum('good', 'bad', 'repared') type. This gives an exception as following:


java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String

What does it mean, the actual value is a string. How can I solve this?


java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
Java

I have a List, which I am trying to use in 2 different ways...

private List<List<List<String>>>
mListSelectedsWeekDAY;

// technique 1
for(int t = 0; t < mListSelectedsWeekDAY.get(0).get(0).size();t++){
    ...
}

// technique 2
List<String> tmpList = mListSelectedsWeekDAY.get(0).get(0);

And my list is populated like this...

mListSelectedsSDAY = new
ArrayList<List<List<String>>>(); 
for (int i = 0; i < mListTimeBand.size(); i++) { 
    List<List<String>> tmp2 = new
ArrayList<List<String>>(); 
    for (int j = 0; j <
mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().size();
j++) { 
        List<String> tmp1 = new ArrayList<String>(); 
        if
(mListTimeBand.get(i).getTimeBandDefList().getTimeBandDefini().get(j).isAllSpeci‌​alDays())
{ 
            for (int t = 0; t < mListSDayType.size(); t++) { 
                tmp1.add(mListSDayType.get(t).getSpecialDayName()); 
            } 
        }
        tmp2.add(tmp1); 
    }

    mListSelectedsSDAY.add(tmp2); 
}

However my code it always giving the following error...

java.lang.ClassCastException: [Ljava.lang.String; cannot be
cast to java.util.List

Could someone please help me understand why this is happening.


ClassCastException: Cannot cast java.sql.Date (id=9010) to java.sql.Timestamp
Java

I am having a problem with a Java 1.4 app.

I am executing a JDBC Qyery-which is 2 date fields in an Oracle database (both the 2 fields I am reading is of type DATE with NULLABLE = false)

SELECT effFrom, effTo FROM myTable WHERE ....

And is exceuted with a JDBCConnection

Object[][] result = JDBCConnection.getSqlObjectArray(query,
bindVals);

I get the data back in my result and loop through it

for (int i = 0; i < result.length; i++) {
 java.sql.Timestamp effFrom = (java.sql.Timestamp ) result[i][0];
 java.sql.Timestamp effTo = (java.sql.Timestamp ) result[i][1];

but it fails converting the object to a java.sql.Timestamp with the error ClassCastException: Cannot cast java.sql.Date (id=9010) to java.sql.Timestamp

(java.sql.Timestamp ) result[i][0]

So I changed the convertion to

java.sql.Date effFrom = (java.sql.Date) result[i][0];

And it is working. All perfect.

But the thing is that my code did not change and the data did not change for the last 6 months atleast.

It did work with the Timestamp conversion up to yesterday and today it is not working with the timestamp but with the Date.

I then went back to the source code repo and seen that it was originally java.sql.Date about 2 years ago and now I basically rolled it back. So clearly there is something that I am missing here.

Is there a way that the JDBC query could mis interpret the data type?

As per Rudi's question what is inside JDBCConnection.getSqlObjectArray()

It has a JdbcDaoSupport class called dao

 public static Object[][] getSqlObjectArray(String sql,
String bind1, String bind2, String bind3) {

        Object[][] a = dao.getSqlObjectArrayImpl(sql, bind1, bind2,
bind3);
        return a;
    }

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.****.db.*****
Java

I am new to spring framework. I am trying to POST JSON data using RESTClient (application/json). But I am getting the following error. (Spring version 3.2)

ERROR :

2015-01-20 10:22:33,262 ERROR
[org.jboss.ejb.plugins.LogInterceptor] RuntimeException in method:
public abstract com.**.db.TnPermissionGroup
com.***.ejb.UserManagerLocal.addPermissionGroup(com.***.db.TnPermissionGroup)
throws java.lang.Exception:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast
to com.***.db.TnPermission
    at
com.***.ejb.UserManagerEJB.addPermissionGroup(UserManagerEJB.java:521)
    at
com.***.ejb.UserManagerEJB.addPermissionGroup(UserManagerEJB.java:495)

JSON Format:

{  
   "name":"Test",
   "tnPermissions":[  
      {  
         "comp_id":{  
            "permGroupId":"2",
            "functionId":"100",
            "operationType":"5"
         },
         "allow":"1"
      }
   ]
}

Controller.java

 /**************** ADD PERMISSIONGROUP
**********************/

    
@RequestMapping(method=RequestMethod.POST,consumes="application/json")
     @ResponseStatus(HttpStatus.CREATED)
     public @ResponseBody Object addPermissionGroup(@RequestBody
PermissionGroupRequestCriteria
permissiongroupRequestCriteria,BindingResult bindingResult) throws
Exception{
         TnPermissionGroup grp = null;

        try{
           
permissiongroupValidator.validate(permissiongroupRequestCriteria,
bindingResult);
            if(bindingResult.hasErrors())
            {
                Map<String,String> fieldErrorMap = new
HashMap<String,String>();
                for(FieldError fieldError :
bindingResult.getFieldErrors())
                {
                     fieldErrorMap.put(fieldError.getField(),
fieldError.getDefaultMessage());
                }
                String localizedErrorMessage =
messageSource.getMessage("permissiongroup.insert.unsuccessful", null,
currentLocale);
                ErrorResponse resp =new
ErrorResponse(localizedErrorMessage);
                resp.setErrorMessages(fieldErrorMap);
                return new
ResponseEntity<ErrorResponse>(resp,HttpStatus.BAD_REQUEST);
            }


            grp = new
TnPermissionGroup(permissiongroupRequestCriteria.getPermGroupId(),permissiongroupRequestCriteria.getName(),permissiongroupRequestCriteria.getDescription(),permissiongroupRequestCriteria.getTnPermissions());

            grp = userDelegate.addPermissionGroup(grp);

        } catch(Exception e){
            String localizedErrorMessage =
messageSource.getMessage("permissiongroup.insert.unsuccessful", null,
currentLocale);
            ErrorResponse resp = new
ErrorResponse(localizedErrorMessage);
            return new
ResponseEntity<ErrorResponse>(resp,HttpStatus.BAD_REQUEST);
        }
        argumentsToReplace[0]= grp.getName();
        String localizedErrorMessage =
messageSource.getMessage("permissiongroup.insert.successful",
argumentsToReplace, currentLocale);
        EmptySuccessResponse resp = new
EmptySuccessResponse(localizedErrorMessage);
        resp.setResource(grp);
        return new ResponseEntity<EmptySuccessResponse>(resp,
HttpStatus.CREATED); 
    }

TnPermissionGroup.java

public class TnPermissionGroup implements Serializable {

    private Integer permGroupId;

    private String name;

    private String description;

    private Set tnPermissions;

    public TnPermissionGroup() {
    }

    public TnPermissionGroup(Integer permGroupId, String name, Set
tnPermissions) {
        this.permGroupId = permGroupId;
        this.name = name;
        this.tnPermissions = tnPermissions;
    }

    /** full constructor */
    public TnPermissionGroup(Integer permGroupId, String name, String
description, Set tnPermissions) {
        this.permGroupId = permGroupId;
        this.name = name;
        this.description = description;
        this.tnPermissions = tnPermissions;
    }

    public Integer getPermGroupId() {
        return this.permGroupId;
    }

    public void setPermGroupId(Integer permGroupId) {
        this.permGroupId = permGroupId;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set getTnPermissions() {
        return this.tnPermissions;
    }

    public void setTnPermissions(Set tnPermissions) {
        this.tnPermissions = tnPermissions;
    }

    public void addPermission(TnPermission perm)
    {
        if (tnPermissions == null) {
            tnPermissions = new HashSet();
        }
        tnPermissions.add(perm);
    }

}

TnPermission.java

  public class TnPermission implements Serializable {

        private com.***.db.TnPermissionPK comp_id;

        private Byte allow;

        /** full constructor */
        public TnPermission(com.***.db.TnPermissionPK comp_id, Byte
allow) {
            this.comp_id = comp_id;
            this.allow = allow;
        }

        /** default constructor */
        public TnPermission() {
        }

        /** minimal constructor */
        public TnPermission(com.***.db.TnPermissionPK comp_id) {
            this.comp_id = comp_id;
        }

        public com.***.db.TnPermissionPK getComp_id() {
            return this.comp_id;
        }

        public void setComp_id(com.***.db.TnPermissionPK comp_id) {
            this.comp_id = comp_id;
        }

        public Byte getAllow() {
            return this.allow;
        }

        public void setAllow(Byte allow) {
            this.allow = allow;
        }
    }

TnPermissionPK.java

public class TnPermissionPK implements Serializable {

    private Integer permGroupId;
    private Integer functionId;
    private Integer operationType;

    /** full constructor */
    public TnPermissionPK(Integer permGroupId, Integer functionId,
Integer operationType) {
        this.permGroupId = permGroupId;
        this.functionId = functionId;
        this.operationType = operationType;
    }

    /** default constructor */
    public TnPermissionPK() {
    }

    public Integer getPermGroupId() {
        return this.permGroupId;
    }

    public void setPermGroupId(Integer permGroupId) {
        this.permGroupId = permGroupId;
    }

    public Integer getFunctionId() {
        return this.functionId;
    }

    public void setFunctionId(Integer functionId) {
        this.functionId = functionId;
    }

    public Integer getOperationType() {
        return this.operationType;
    }

    public void setOperationType(Integer operationType) {
        this.operationType = operationType;
    }
}

Why JSON data POST is not parsing. I think JSON format is wrong. Help me please.



Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .