Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Need help with "Invalid character constant" error, etc.

Hi, here is my tMap expression:
table_a.column_x == 0000 ? 'UNK' : String.valueOf(table_a.column_x)

Getting an "invalid character constant" error on this
column_x is of data type short and I'm wanting to change it to string
Occasionally my source system gives a value of '0000'
Note: The source table column is actually of MySQL data type year by the way, but I'm just calling it a short in Talend; if this is a part of my problem then I welcome solutions
The reason for all the dancing around is that Java doesn't accept a year of '0000' as a valid Java date, which is why I thought to try a short, but it seems the '0000' was still causing problems
Thanks for any advice 0683p000009MACn.png
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

hi,
table_a.column_x.equals("0000") ? "UNK" : table_a.column_x

"0000" should also to be a String to keep 'precision' (4 digits) .
Convert it with tconvert before expression.
regards
laurent

View solution in original post

8 Replies
Anonymous
Not applicable
Author

Hi
I would like to read it as a string, and then check the string if it contains "0000", if so, set it to null or other value, if not, parse the string to Date if needed.
Shong
Anonymous
Not applicable
Author

I am not sure, but the error is referring to 'UNK' as invalid char constant !!!
What is datatype of your output column?
Vaibhav
Anonymous
Not applicable
Author

In Java single quotes indicate a Char, double quotes for String. 'UNK' is not a valid Char. 'U' is a valid Char. "UNK" is a valid String.
Anonymous
Not applicable
Author

hi,
table_a.column_x.equals("0000") ? "UNK" : table_a.column_x

"0000" should also to be a String to keep 'precision' (4 digits) .
Convert it with tconvert before expression.
regards
laurent
Anonymous
Not applicable
Author

Ok thanks very much for all of these ideas, I'll mark the thread resolved 0683p000009MACn.png
Anonymous
Not applicable
Author

Hi,
What was the problem and how you solved it, could you pl explain it here?
Thanks
Vaibhav
Anonymous
Not applicable
Author

Hi, I ended up changing it back to a short/smallint, saved some bytes that way in my DB
However, kzone's answer looks reasonable, though I didn't try it ... did it not work for you?
Anonymous
Not applicable
Author

However, kzone's answer looks reasonable, though I didn't try it

arhhgghhh ... Damned 0683p000009MA9p.png