Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
sivaa_m
Contributor
Contributor

[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
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

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

3 Replies
Anonymous
Not applicable

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
sivaa_m
Contributor
Contributor
Author

Hi,
Thanks for the reply. The issue got resolved.
Can you explain me the syntax which you have given.
Thanks
Siva
Anonymous
Not applicable

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