Apache Camel: bean component - transforming sql resultset to csv: handling NULL values

630 views Asked by At

i try to convert an sql resultset to csv file. i'm using a bean component on apache camel project like below:

public StringBuilder ind_tocsv(Exchange exchange) {

        StringBuilder csv = new StringBuilder();
        List<?> received = exchange.getIn().getBody(List.class);

        for(int i = 0; i < received.size(); i++)
        {
            Map<String,Object> row = (Map<String,Object>) received.get(i);
            csv.append(row.get("ISIN"));
            csv.append(";").append(row.get("SECT_FIN"));
            csv.append(";").append(row.get("AN1"));
          }
        return csv;
}

and this is my route: blueprint.xml:

<from uri="direct:IND_RES"/>
        <to uri="sql:exec [xp_ind]?dataSource=afbl_datasource"/>
        <to uri="bean:ngtrend.agentsynchro.Transformer?method=ind_tocsv(Exchange)"/>
        <log message="${body}" />
        .....

the problem is that if the row value from resultset = NULL, after transformation i get "NULL" instead of empty value

exemple: if SECT_FIN = NULL the output (csv file) will be like this: 12005;NULL;2016 instead of 12005;;2016

How can i fix this ?

0

There are 0 answers