Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

Accepted Solutions
TRF
Champion II
Champion II

Just add a tJavaRow after each tFilterRow to compute the number of rows using a dedicated global variable.
This way, you may avoid to call the txxxxxOutput components when the corresponding number of rows is equal to 0.
This is a solution, many other may exist as TOS is very adaptable.
TRF

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Hi,
Use the Java equals() function instead of the == operator for string comparisons.
( (String)globalMap.get("isLocked") ).equals("N")
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

try updating your if condition to this.
if (globalMap.get("IsLocked").toString().equals("N")){ System.out.println("Then"); }
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

Hii everyone,
I am very new to talend. I have a flat file in .csv form. In the flat file there is a field which can have values like lms/spar/max. It is mandatory that at least once these three names has to occur in the flat-file. If the File don't have any one of this option, I have to send a mail. What should I do?
I tried something like this:
FileInputDelimited -> tjavarow ->runif -> tsendmail
I tried using flag to check if any of these option are not present. But its showing error as 'flag cannot be resolved to a variable'!
please tell me a way out to solve this problem.
TRF
Champion II
Champion II

Hi,
Use a tFilter to get records with one of the three values mls/spar/max.
If no row goes to the the filtered output, then no records contains the desired values and you can go with tSendMail.
No tJavaRow required for this.
Regards,
TRF
Anonymous
Not applicable
Author

Hi,
Thanks a bunch TRF for your suggestion. But I am already using three filters to send the LMS/SPAR/MAX into its respective database table. So now how should I check whether there is data passing through it or not. 
my whole process looks like this
FileInputDelimited -> tmap -> tfilterrow -> lms data into lms database 
                                 |_ -> tfilterrow -> spar data into spar database 
                                 |_ -> tfilterrow -> max data into max database 
Now how should I add a check in tfilter row to check if no row is passing through it into the database.
TRF
Champion II
Champion II

Just add a tJavaRow after each tFilterRow to compute the number of rows using a dedicated global variable.
This way, you may avoid to call the txxxxxOutput components when the corresponding number of rows is equal to 0.
This is a solution, many other may exist as TOS is very adaptable.
TRF
Anonymous
Not applicable
Author

Hi,
I wanted the flag..I need to use it in the further process. 
My Code which I am inserting in tjavarow  is as below:
int flag1=0, flag2=0;
if (output_row.OU_CODE.equals("LMS"))
flag1 = 1;
else (output_row.OU_CODE.equals("SPAR"))
flag2 = 1;
But tjavarow is giving me  errors like.. 


0683p000009MDIi.png
Please help me write this code well so that tjavarow wont give me errors. Also After tjava row I have runif condition which will check if flag1==0 || flag2==0 and then send a mail.