SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-44
Character String Data Types
Comparing Character String Data With an SQL/MX ISO88591 Column
Consider an SQLJ program that modifies an SQL/MX table with a column named
LOCATION that stores characters in ISO88591 character-set format:
CREATE TABLE samdbcat.persnl.dept
( deptum NUMERIC (4) UNSIGNED
NO DEFAULT
NOT NULL
...
,location VARCHAR (18) CHARACTER SET ISO88591
...
In the SQLJ program, code the host variable declaration and DELETE statement as:
String city = new String("Chicago"); /* String literal encoded
as UCS2 */
...
#sql {DELETE FROM dept
WHERE location = :city};
...
SQL/MX implicitly converts the UCS2 character string to ISO88591 format when
comparing it with the ISO88591 column because the characters in the UCS2 string
literal are within the range of the ISO88591 character set.
This DELETE statement fails because the characters in the UCS2 string literal are not
within the range of the ISO88591 character set and cannot be compared with the
ISO88591 column:
For more information, see Host Variables and Expressions on page 3-27 and
Character String Literals on page 3-45.
String city = new String(" "); /* String literal encoded
as UCS2 */
...
#sql {DELETE FROM dept
WHERE location = :city};
...