mariusz2108
mariusz2108

Reputation: 881

DB2 on AS400 encoding issue with jt400

I use jt400 to get data from database on as400 - db2.

My database use ccsid 37 encoding. I have problem with polish letters only. How can I force jt400 to use proper encoding?

I tried

jdbc:as400://MY_SYSTEM/LIBRARY;translate binary=true

AS400Text converer = new AS400Text(stringFromDb.length(), 37);
String stringAfterConversion = converter.toObject(stringFromDb.getBytes());

but it doesn't work

Upvotes: 0

Views: 4287

Answers (2)

jmarkmurphy
jmarkmurphy

Reputation: 11473

CCSID 37 is English and does not contain certain Polish characters. The Polish CCSID is 1153, or 870 (without Euro symbol).

You can see the symbols contained in CCSID 37 (Character set 697) here: ftp://ftp.software.ibm.com/software/globalization/gcoc/attachments/CS00697.pdf

You can see the symbols contained in CCSID 1153 (Character set 1375) here: ftp://ftp.software.ibm.com/software/globalization/gcoc/attachments/CS01375.pdf

If the database field contains CCSID 37 you will not be able to store the characters that are missing CCSID from 1153. Common characters will be converted. You could try changing your database to use UTF-16 or CCSID 1200. That contains all the characters in CCSID 37 and CCSID 1153.

Upvotes: 3

Charles
Charles

Reputation: 23783

If things are set up properly, you shouldn't need to do any manual conversion. The DB and JDBC driver handle it for you.

You say your DB is using CCSID 37, which is English as used in the US, Canada, Netherlands, Portugal, Brazil, New Zealand, Australia.

To handle Polish characters, you'd probably need CCSID 870 (per Language identifiers and associated default CCSIDs)

However, CCSID is assigned per column. So everything in that column in that table would need to be in one or the other CCSID.

If you need to store both English & Polish in the same column in the same table, then the best option would be to change the column(s) to Unicode.

Alternatively, you could flag the data as "binary" CCSID 65535, so that the system won't try to convert it. You'd need translate binary=false and your application would be responsible for knowing which records were in English and which were in Polish. So you'd need some additional flag field in the record.

Upvotes: 2

Related Questions