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.Date
s are not compatible with Sybase datetime
, as Java’s String
s 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.Date
s cast.