JDBC Type 4 Driver 1.1 Programmer's Reference

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
A problem can occur when selecting the inserted row. If you were to select the same row as inserted, and call the
getString() method, the resulting string would not match the original string. For example:
rs = pStmt.executeQuery(“Select c1 from t1”);
rs.getString(1);
Internally, the Type 4 driver creates a string using the following pseudo code:
byte[] outB1 = getColumn1(); //
where getColumn1() returns the following stored bytes:
0x83 0x42 0x83 0x42 0x20 0x20 0x20 0x20 0x20 0x20 0x20 0x20
The driver creates a String object.
String s1 = new String(outB1, “SJIS”);
The resulting String object has the following UCS2 encoding:
0x30 0xA2 0x30 0xA3 0x00 0x20 0x00 0x20 0x00 0x20 0x00 0x20 0x00 0x20 0x00
0x20 0x00 0x20 0x00 0x20
The resulting string would be 10 characters (2 characters following by 8 UCS2 spaces). This length is 4 characters more than
the column length (which is 6).
Localizing Error Messages and Status Messages
The Type 4 driver supports Internationalization through resource bundles for localized error messages and status messages. The
driver uses a set of static strings from a property file to map error messages and status messages to their textual representation.
File-Name Format for the Localized-Messages File
The property file that has the messages must have a file name in the form:
SQLMXMessages_xx.properties
where xx is the locale name. The locale name is defined by the current default locale or by the language property.
The Type 4 driver is shipped with an error messages and status messages property file that contains the textual representation
of errors and status messages for the English locale. The file is named SQLMXMessages_en.properties.
Localized-Message String Format
A localized message file contains strings in the form: