Author |
Message
|
dan2WMB |
Posted: Mon Dec 13, 2010 10:02 pm Post subject: Need help on ESQL-to-Java mapping |
|
|
Novice
Joined: 06 Aug 2010 Posts: 12
|
My requirement is to print a String(with LineFeed) in java method. I am trying to call a java function from ESQL as follows
DECLARE newLineFeed CHARACTER CAST(X'0A' AS CHARACTER CCSID 1208);
DECLARE msg CHARACTER 'test msg';
SET msg = msg || newLineFeed || 'msg in the new line';
CALL logInfo(msg);
.
.
.
CREATE Function logInfo (IN msg CHAR)
LANGUAGE JAVA
EXTERNAL NAME "com.Logger.info";
When i try to print this "msg" in the Logger class, i am getting the output as "test msg(some junk character)msg in the new line".
I expected the output should be like following.
test msg
msg in the new line
I also tried to use '\r\n' for the line feed, it is also not working.
Please help me to print a String with new line feed. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Dec 14, 2010 12:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Shouldn't CCSID 1208 have 0x0d0a as new line?
Also you are not passing a String to Java. You are passing a mixed CCSID value to Java where the text is in unicode (String) and the line feeds are in UTF-8 ? That you are printing some strange char and then the line feed is expected.
Try and just add LF to your string like this:
Code: |
SET msg = msg || LF || 'msg in the new line'; |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kimbert |
Posted: Tue Dec 14, 2010 1:29 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Shouldn't CCSID 1208 have 0x0d0a as new line? |
I don't think the character encoding implies very much about the newline convention. CCSID 1208 ( UTF-8 ) can encode a carriage return, newline or a pair equally well. |
|
Back to top |
|
 |
mgk |
Posted: Tue Dec 14, 2010 1:48 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
I don't think the character encoding implies very much about the newline convention. CCSID 1208 ( UTF-8 ) can encode a carriage return, newline or a pair equally well |
Agreed, UTF-8 can encode a newline in different ways.
Quote: |
When i try to print this "msg" in the Logger class, i am getting the output as "test msg(some junk character)msg in the new line". |
However, the application used to display the output may not understand a single X'0A' on Windows.
Quote: |
Also you are not passing a String to Java. You are passing a mixed CCSID value to Java where the text is in unicode (String) and the line feeds are in UTF-8 ? |
However, this is not the case, as the ESQL is clever enough to convert the 1208 X'0A' into unicode before the concatenation taken place.
As fjb_saper says you will need to use X'D' as well, so your code should look like this:
Code: |
DECLARE newLineFeed CHARACTER CAST(X'0D0A' AS CHARACTER CCSID 1208); |
Kind Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
dan2WMB |
Posted: Tue Dec 14, 2010 5:56 am Post subject: |
|
|
Novice
Joined: 06 Aug 2010 Posts: 12
|
cool....it worked as you told mgk. Thnaks you very much. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Dec 14, 2010 6:26 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
|