One Star

tJava returning array of Strings

I have a Java class that returns array of strings and I would like to write the values of the array elements to a database table.
For example tJava creates an array:
a = 'test1'
a = 'test2'
a = 'test3'
a = 'test4'
a = 'test5'

and I would like to insert all of these values in separate rows in a table.
Is this possible with TOS?
Thanks
Magi
8 REPLIES
Community Manager

Re: tJava returning array of Strings

Hi
If you want to insert the values into table, you can use the tJavaRow component and add new columns.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tJava returning array of Strings

Thank, but I think that it wouldn't work because the number of array elements is not know at design time and because I need one new column that contains all the values of the array and not one column for each value.

Magi
Employee

Re: tJava returning array of Strings

This is the purpose of the tForEach component.
Regards,
One Star

Re: tJava returning array of Strings

OK, I can connect my tFileList component to a tForEach component, but then I cannot connect my tForEach component to tJavaRow. Can you please explain how should they be connected?
The scenario is the following:
For a list of files I am executing a piece of Java that returns an ArrayList. So, if I have 10 files I have to execute the Java code 10 times and get 10 ArrayLists that need to be merged then in one list and put in a DB table.
Thanks
Magi
Employee

Re: tJava returning array of Strings

Here is a simple job doing this process.
I'm maybe wrong in the tJavaRow but I'm sure you understand your process more than me ;-)
Regards
One Star

Re: tJava returning array of Strings

Thanks, this helped but not enterely.
When I say merging, I in fact think of merging the arraylists.
If i have 3 files, there will be 3 array lists generated.
For example,
for file1 I get
a = 'test1'
a = 'test2'
a = 'test3'
a = 'test4'
a = 'test5'
for file 2 I get
b = 'testing1'
b = 'testing2'
b = 'testing3'
and for file 3 I get

c = 'tst1'
c = 'tst2'
c = 'tst3'
c = 'tst4'

What I want to get are the following rows in the mysqltable:
column1
'test1'
'test2'
'test3'
'test4'
'test5'
'testing1'
'testing2'
'testing3'
'tst1'
'tst2'
'tst3'
'tst4'
I hope this explains the problem better. Can you plese look into this?

Thanks
Magi
Employee

Re: tJava returning array of Strings

In the tJavaRow, add a separator between the myString in the mergedString :
mergedString+=myString+",";
and add a tNormalize after the tJavaRow.
Regards,
One Star

Re: tJava returning array of Strings

Many Thanks
I tested this and it works fine.
Magi.