[resolved] String index out of range

Highlighted
Four Stars

[resolved] String index out of range

Hi,
I am new to talend. I tried to insert the data from source to target. both my source & target are mssql. I used the tmap for mapping between source & target. In the target i need to substring the source values. so i tried the following in the tmap
column_name.substring(start poisitiion,end position).
While execution I am getting the below given error.
Exception in component tMap_1
java.lang.StringIndexOutOfBoundsException: String index out of range: 24
at java.lang.String.substring(Unknown Source)
at edw.psp_dim_0_1.PSP_DIM.tMSSqlInput_1Process(PSP_DIM.java:1015)
at edw.psp_dim_0_1.PSP_DIM.runJobInTOS(PSP_DIM.java:1463)
at edw.psp_dim_0_1.PSP_DIM.main(PSP_DIM.java:1331)
Kindly suggest. Please find the screenshot of the job design & error

Accepted Solutions
Highlighted
One Star

Re: [resolved] String index out of range

Hi,
It seems one of the input strings isn't the supposed length of 24 positions. substring will return with an exception in this case. You could use the following syntax:
column_name.substring(start poisitiion, Math.min(end position, column_name.length()))

Hope this helps.
Regards,
Arno

View solution in original post


All Replies
Highlighted
One Star

Re: [resolved] String index out of range

Hi,
It seems one of the input strings isn't the supposed length of 24 positions. substring will return with an exception in this case. You could use the following syntax:
column_name.substring(start poisitiion, Math.min(end position, column_name.length()))

Hope this helps.
Regards,
Arno

View solution in original post

Highlighted
Four Stars

Re: [resolved] String index out of range

Hi,
Thanks for the reply. The issue got resolved.
Can you explain me the syntax which you have given.
Thanks
Siva
Highlighted
One Star

Re: [resolved] String index out of range

Hi,
Sure, what is does is get the characters starting at "start position" (being 0 in your sample I see) and ending at either the last character of the string, or the character at position "end position" (being 24 in your sample). So for a String with length 20 only 20 character will be captured while for a string with length 30, 24 characters will be captured.
Hope this helps.
Regards,
Arno

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog