Search
Calendar
August 2020
S M T W T F S
« Sep    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Your widget title
Archives

Posts Tagged ‘Operand type clash’

PostHeaderIcon Operand type clash: java.util.Date is incompatible with DATETIME

Case

With Mule ESB, I try to integrate an object of type java.util.Date into a column of type datetime in a Sybase DB table.
I get the following error:

 java.sql.SQLException: Operand type clash: java.util.Date is incompatible with DATETIME

Explanation – Fix

The stacktrace is explicit: java.util.Dates are not compatible with Sybase datetime, as Java’s Strings are not compatible with Sybase numeric(10, 3) for instance.
To fix the issue, you have to cast your java.util.Date as java.sql.Date or java.sql.Timestamp. The cast is very easy to perform:

private static java.sql.Timestamp javaDate2SqlTimestamp(java.util.Date javaDate){
final java.sql.Timestamp answer = new java.sql.Timestamp(javaDate.getTime());
return answer;
}

The method is quite similar for java.sql.Dates cast.