String index out of range error

Highlighted
Four Stars

String index out of range error

Hello,

 

I am trying to read data from xml file and write them to Mysql db. In my db House_no field's data type is String(40). In xml file there are some house no values that longer than 40 and i want to cut all the values that are greater than 40.
so i try the code below in tMap but i got "java.lang.StringIndexOutOfBoundsException: String index out of range: 40 at java.lang.String.substring(Unknown Source)" error?
row4.house_no.length()>40 ?"" : row4.house_no.substring(0,40)
Do you have any idea what cause this error, or a better way to take 0-40 character without using tJavaRow.

 

thanks

iosman

 

 

___________________________

0xc000000f

Nine Stars JR
Nine Stars

Re: String index out of range error

Try putting you ternary statement in the correct order and add a "null" check to it:

row4.house_no != null && row4.house_no.length() > 40 ? row4.house_no.substring(0,40) : row4.house_no

 

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

The Forrester Wave: Strategic iPaaS and Hybrid Integration Platforms, Q1 2019

Find out how Forrester rate different iPaaS and Hybrid Integration Platforms

Read

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now