Question

I'm actually working on a talend job. I need to load from an excel file to an oracle 11g database.

I can't figure out how to break a field of my excel entry file within talend and load the broken string into the database.

For example I've got a field like this:

toto:12;tata:1;titi:15

And I need to load into a table, for example grade:

| name | grade |
|------|-------|
| toto |12     |
| titi |15     |
| tata |1      |
|--------------|

Thank's in advance

Was it helpful?

Solution

In a Talend job, you can use tFileInputExcel to read your Excel file, and then tNormalize to split your special column into individual rows with a separator of ";". After that, use tExtractDelimitedFields with a separator of ":" to split the normalized column into name and grade columns. Then you can use a tOracleOutput component to write the result to the database.

While this solution is more verbose than the Java snippet suggested by AlexR, it has the advantage that it stays within Talend's graphical programming model.

OTHER TIPS

for(String pair : str.split(";")) {
    String[] kv = pair.split(":");
    // at this point you have separated values
    String name = kv[0];
    String grade = kv[1];

    dbInsert(name, grade);
}

Now you have to implement dbInsert(). Do it either using JDBC or using any higher level tools (e.g. Hivernate, iBatis, JDO, JPA etc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top