cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping lookup for file adapter

Former Member
0 Kudos

Hi Experts,

I am doing JDBC to File Scenario, sender side i got the company name field receiver side i got company code field.

There is a file in the XI server it contains list of all company name and copany codes.

i need to take the company code from the file based on company name from sender side during the mapping.

Can anybody suggest me how can i achieve this?

Kind Regards,

Kiran.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member192892
Active Contributor
0 Kudos

Hi, kiran,

You need to write a java code which will parse the file and retrieve the data. The methods of this java class should be called during mapping whici would rteturn you the company code...

If you can be more specific about the data paresent in the file, then it'd be more helpful

Former Member
0 Kudos

Hi Varun,

Thanks for your quick reply.

The file is comma separated text file, the file is like this.

<b>company code,company name,person responsible,vat,postal address</b>

Can you please supply me the code in UDF.

Kind Regards,

Kiran

former_member192892
Active Contributor
0 Kudos

Kiran,

Sprry for late reply, had gone 4 lunch

Pl add this in ur UDF..The input to UDF would be company name..

Change the location of your file accordingly in the code

The imports are

java.io.BufferedReader;

java.io.FileReader;

java.io.InputStreamReader;

java.util.HashMap;

String companyCode = "";

HashMap fileMap = new HashMap();

BufferedReader reader = new BufferedReader(new FileReader("C:
ROOT
MyFolder\file.txt"));

String line = "";

while((line = reader.readLine())!=null)

{

String<i>[]</i> lineArray = line.split(",");

fileMap.put(lineArray<i>[1]</i>, lineArray<i>[0]</i>);

}

companyCode = (String) fileMap.get(companyName);

return companyCode;

Former Member
0 Kudos

hi varun,

iam getting fileNotFound Exception.

I did place the file same location(C:\ROOT\MyFolder\file.txt).

Can you please help me out.

Kind Regards,

Kiran

former_member192892
Active Contributor
0 Kudos

Plz modify slightly

BufferedReader reader = new BufferedReader(new FileReader("C:
ROOT
MyFolder
file.txt"));

There was one more '
'..

Please note to give two slashes and not 1

Thanks

Former Member
0 Kudos

hi varun

still iam getting fileNotfound Exception.

Kind Regards,

Kiran

Former Member
0 Kudos

Hi varun,

i think system is not looking the file in this path.

should i need to set any classpath??

should i need to place the file in another path??

i tried in my local machine same code its working. thanks for your code.

Kind Regards,

Kiran

former_member192892
Active Contributor
0 Kudos

Hi Kiran,

About the file not found exception, I think i need to make the code generic...

The code i gave was for windows machines...

Please use this code. Also find out the JAVA.HOME folder in your XI server..

Usually it would be C:\j2sdk1.4.2_12\jre.

Place your file here and name it file.txt.

String companyCode = "";

String filePath = System.getProperty("java.home");

filePath = filePath + java.io.File.separator + "file.txt":

HashMap fileMap = new HashMap();

BufferedReader reader = new BufferedReader(new FileReader(filePath));

String line = "";

while((line = reader.readLine())!=null)

{

String<i>[]</i> lineArray = line.split(",");

fileMap.put(lineArray<i>[1]</i>, lineArray<i>[0]</i>);

}

Former Member
0 Kudos

Hi Varun,

In XI server JAVA_HOME(Environment variable) is set to C:\Program Files\java\j2sdk1.4.2_13. i did place the file in this folder only.

but still iam getting same fileNotFound Exception.

Kin regards,

Kiran