javautf-8db2ibm-midrangedb2-400

Unable to convert bytes from charset 65535 in to Japanese (5035)


I have a character set conversion issue:

I am updating Japanese Kanji characters in DB2 in iSeries system with the following conversion method:

AS400 sys = new AS400("<host>","username","password");
CharConverter charConv = new CharConverter(5035, sys);
byte[] b = charConv.stringToByteArray(5035, sys, "試験");
AS400Text textConverter = new AS400Text(b.length, 65535,sys);

While retrieving, I use the following code to convert & display:

CharConverter charConv = new CharConverter(5035, sys);
byte[] bytes = charConv.stringToByteArray(5035, sys, dbRemarks);
String s = new String(bytes);
System.out.println("Remarks after conversion to AS400Text :"+s);

But, the system is displaying garbled characters while displaying. Can anybody help me to decode Japanese characters from binary storage?


Solution

  • Thanks a lot Jon and Buck Calabro !

    With your clues, I have succeeded with the following approach:

    String remarks = new String(resultSet.getBytes("remarks"),"SJIS");
    byte[] byteData = remarks.getBytes("SJIS");
    CharConverter charConv = new CharConverter(5035, sys);
    String convertedStr = charConv.byteArrayToString(5035, sys, byteData);
    

    I am able to convert from string. I am planning to implement the same with JPA, and started coding.