Mule4 - Resolving Database Date and DateTime Type Error while Inserting.
Let's see how to resolve error while inserting database date and datatime errors in Mule4 while inserting data into database.
%dw 2.0
output application/json
---
"billing_date": $.billing_date as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSX"} as String {format : "yyyy-MM-dd"} ,
"reason": "DB:QUERY_EXECUTION",
"message": "java.sql.SQLException: Data type mismatch. (2024-02-06)"
Column Declared as Date in database for the table example as follows:
TRANDATE DATE DEFAULT '1970-01-01' NOT NULL,
Dataweave: ( assuming the incoming billing_date is coming as DateTime( example: "2024-02-06T11:02:05.237Z") and converting to Date in String format "yyyy-MM-dd"
output application/json
---
"billing_date": $.billing_date as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSX"} as String {format : "yyyy-MM-dd"} ,
to convert RAML datetime type DB date time
%dw 2.0
output application/json
---
output application/json
---
"date_updated": $.date_updated as DateTime {
format: "yyyy-MM-dd'T'HH:mm:ss.SSSX"
} as DateTime {
format : "yyyy-MM-dd HH:mm:ss"
}
error while executing :
"message": "java.sql.SQLException: Data type mismatch. (2024-02-06)"
How to fix this error:
While binding data in the sql query text to databse connector pass the "billding_date" as follows:
TO_DATE(:billing_date,'YYYY-MM-DD')
Comments
Post a Comment