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.

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"

%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"} ,


to convert RAML datetime type DB date time
%dw 2.0
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 : 

"reason": "DB:QUERY_EXECUTION",
"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

Popular posts from this blog

Mulesoft Certified Developer-Level2 - Study Material

Mulesoft - Salesforce Composite Request and Composite Graph Request API Calls

Mulesoft -- Persistent Queues, Batch Job Queues, Object Store V2(OSV2) , Persistent Object Store, Non-Persistent Object Store in CloudHub 1.0