SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-43
Character String Data Types
Assigning Character String Data to an SQL/MX UCS2 Column
Consider an SQLJ program that modifies an SQL/MX table with a column named
LOCATION that stores characters in UCS2 character-set format:
CREATE TABLE samdbcat.persnl.dept_internatl
( deptum NUMERIC (4) UNSIGNED
NO DEFAULT
NOT NULL
...
,location VARCHAR (18) CHARACTER SET UCS2
...
In the SQLJ program, code the host variable declaration and UPDATE statement as:
Unicode is the appropriate encoding for Japanese characters to be assigned to or
compared with an SQL/MX UCS2 character-set column. To ensure that the character
string literal is encoded properly, set the -encoding option to UTF-16BE or
UnicodeBigUnmarked during translation of the SQLJ program. For more information,
see -encoding on page 5-22.
In the same SQL/MX UCS2 column, an SQLJ program can insert a character string
encoded in ISO88591 character-set format:
String city = new String("Chicago"); /* String literal encoded
as ISO88591 */
...
#sql {INSERT INTO dept_internatl
(deptnum, deptname, manager, rptdept, location)
VALUES (:deptNum, :deptName, :manager, :rptDept,
:city)};
...
SQL/MX implicitly converts the ISO88591 character string to USC2 format when
assigning it to the UCS2 column.
String city = new String(" "); /* String literal encoded
as UCS2 */
...
#sql {UPDATE dept_internatl
SET location = :city
WHERE deptnum = 3000};
...