• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Question about TJavaRow comparing string values.

#1 2011-05-04 10:04:44

ataris
Member
Registered: 2011-05-03
Posts: 16

[resolved] Question about TJavaRow comparing string values.

I need to compare global variable value with string value. And if condition JOB must be stopped.

I did this on TJavaRow:

System.out.println("My value " + globalMap.get("IsLocked")) ;
if (globalMap.get("IsLocked") == "N") {System.out.println("Then");}
else {throw new RuntimeException("----Raise error-------");};

Why condition doesn't work? It raises error while Println returns " My value N".

Global variable type is Char.

Offline

#2 2011-05-04 13:02:04

walkerca
Member
Company: Bekwam, Inc.
Registered: 2011-01-12
Posts: 253
Website

Re: [resolved] Question about TJavaRow comparing string values.

Hi,

Use the Java equals() function instead of the == operator for string comparisons.

( (String)globalMap.get("isLocked") ).equals("N")


Visit bekwam.blogspot.com for Talend topics and tutorials.  Twitter @bekwaminc for updates.

Offline

#3 2011-05-05 07:49:35

ataris
Member
Registered: 2011-05-03
Posts: 16

Re: [resolved] Question about TJavaRow comparing string values.

Hi walkerca,

now code looks like:

System.out.println("My value " + globalMap.get("IsLocked")) ;
if (( (String)globalMap.get("IsLocked") ).equals("N")) {System.out.println("Then");}
//else {System.out.println("Then2");};
else {throw new RuntimeException("----Raise error-------");};

But i get error:
Exception in component tJavaRow_2
java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String

When i remove (String) option it doesn't compares values in right way. I mean runs "---- Raise error ---" while value is "N" Println returns - My value N

I tried IsLocked in MSSQLInput Edit schema change DB type between CHAR and VARCHAR but it didn't help..

EDIT : need to change Type to String in Edit Schema.

Thanks.

Last edited by ataris (2011-05-05 08:09:43)

Offline

#4 2011-05-05 17:15:48

ashu
Member
Registered: 2010-07-14
Posts: 133

Re: [resolved] Question about TJavaRow comparing string values.

try updating your if condition to this.

Code:

if (globalMap.get("IsLocked").toString().equals("N")){ System.out.println("Then"); }

Offline

#5 2011-05-06 00:41:22

walkerca
Member
Company: Bekwam, Inc.
Registered: 2011-01-12
Posts: 253
Website

Re: [resolved] Question about TJavaRow comparing string values.

Was isLocked set with a 'N' rather than "N" (single versus double quotes)?  Make sure that it was actually loaded in the globalMap as a String.


Visit bekwam.blogspot.com for Talend topics and tutorials.  Twitter @bekwaminc for updates.

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » [resolved] Question about TJavaRow comparing string values.

Board footer

Powered by FluxBB