JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.2 (H06.25+, J06.14+)
Trimming Padding for Fixed-Length Character Columns
Retrieved values might be longer than inserted values for fixed-length character columns that use
the KANJI character set or KSC5601 character set in SQL/MP tables. This subsection describes:
• “Reinserting a Row that Has Fixed-Length Character Items” (page 31)
• “Discrepancy in Length Caused by Padding Character Causes” (page 31)
Under most circumstances (for example, when the default Kanji=SJIS property key-value is set),
the padding characters can be inserted and selected from the database without error.
This is an advanced topic on character-set manipulation on SQL/MP tables.
Reinserting a Row that Has Fixed-Length Character Items
NOTE: The length of a retrieved string might not be correct if the associated column is double-byte
and fixed length in SQL/MP tables (for example KANJI and KSC5601). The number of padding
characters might be more than expected.
To avoid this length problem, ensure that the program trims any trailing white spaces before
reinserting such a row before calling the setString() method.
Discrepancy in Length Caused by Padding Character Causes
SQL/MP tables containing fixed-length CHAR columns use an ASCII space character (0x20) as a
padding character. Double-byte character columns (KANJI and KSC5601) use two ASCII space
characters (0x2020) as a padding character. UCS2 uses a single UCS2 space (0x0020) as a
padding character.
The 0x2020 character is not a legal character in the Kanji character set, but 0x2020 does represent
two legal characters (two spaces) in the SJIS character set. Under most circumstances the padding
characters can be inserted and selected from the database without error (for example, when the
default Kanji=SJIS property key-value is set).
For example, the pseudo code for an insertion into a table that has a column defined as CHAR(6)
character set KANJI, has the following behavior:
byte b1 = new byte[4];
b1[0] = 0x83; \___ Katakana letter A
b1[1] = 0x41; /
b1[2] = 0x83; \___ Katakana letter small i
b1[3] = 0x42; /
String k1 = new String(b1, “SJIS”);
Internally, the JVM stores k1 as UCS2 in 4 octets (bytes). The UCS2 encoding would be:
0x30 0xA2 0x30 0xA3
An SQL insert statement is prepared:
pStmt = conn.PrearedStatement(“insert into t1 values (?)”);
The statements parameter is set to the string:
pStmt.setString(1, k1);
Internally, the Type 4 driver creates an array of bytes by using the following pseudo code:
byte inB = k1.getBytes(“SJIS”);
int colLen = 12; // i.e. the length of the column (6) times the max length of each character (2)
int padLen = colLen – inB.length; // inB.length = 4 (2 characters times 2 bytes per character)
inB = inB + 0x20 for padLen bytes;
The resulting insert has the following hexadecimal pattern:
0x83 0x42 0x83 0x42 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20
Internationalization (I18N) Support 31










