cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC lookup Using UDF - error class java.math.BigDecimal:null incompatible with class java.lang.String:null

former_member181962
Active Contributor
0 Kudos

Hi experts,

   I have requirement to write a query on a Oracle table using a UDF.

This query can return multiple records.

However i get an error "class java.math.BigDecimal:null incompatible with class java.lang.String:null"

I am able to execute the same query using SQL Developer tool without any issues.

here is the code that i use:

//dfrunid is an array of strings (Input)

String Query = " ";

Channel channel = null;

DataBaseAccessor accessor = null;

DataBaseResult resultSet = null;

MappingTrace trace = container.getTrace();

// Query to retrieve the PROP value for the particular source value passed.

Query ="Select DFO_ID from mn_df_object where DFO_ID_PARENT="+dfrunid[0];

try{

//Determine a channel, as created in the Configuration

channel = LookupService.getChannel("<Business Service>","<Channel Name>");

//Get a system accessor for the channel. As the call is being made to an DB, an DatabaseAccessor is obtained.

accessor = LookupService.getDataBaseAccessor(channel);

//Execute Query and get the values in resultset

resultSet = accessor.execute(Query);

for(Iterator rows = resultSet.getRows();rows.hasNext();){

Map rowMap = (Map)rows.next();

result.addValue((String)rowMap.get("DFO_ID"));

}

}

catch(Exception ex){

result.addValue(ex.getMessage());

}

finally{

try{

if (accessor!=null) accessor.close();

}

catch(Exception e){

result.addValue(e.getMessage());

trace.addInfo(e.getMessage());

}}

Best Regards,

Ravikanth Talagana

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

The details given are not completely sufficient to analyze thoroughly. But I have a question.

1) What is your data type defined for the column name DFO_ID in the table?  Is it Big decimal?  If so, then you need to check the following line

result.addValue((String)rowMap.get("DFO_ID"));

Because you cast the bigdecimal to string.

2) What is the value the dfrunid[0] returns?  If this returns string then you need to use  quote inside the query. Check the value type and write below query accordingly.

Query ="Select DFO_ID from mn_df_object where DFO_ID_PARENT="+dfrunid[0];

Example:

Query = "Select DFO_ID from mn_df_object where DFO_ID_PARENT=' " + dfrunid[0] + " ' ";

Hope this helps.

former_member181962
Active Contributor
0 Kudos

Thanks Bhaskar and Inaki..for pointing me to the right solution.

It helped fixing the issue.

Best Regards,

Ravi

Answers (2)

Answers (2)

iaki_vila
Active Contributor
0 Kudos

Hi Ravi,

To cast a Big Decimal to String you should use the method toString() in result.addValue((String)rowMap.get("DFO_ID"));

Regards.

Former Member
0 Kudos

as seen from error message, you are having issue in casting from bigdecimal to string, check your datatype of the fields and handle it using quote ..