Wrong codepoints for non-ASCII characters inserted in UTF-8 database using CLP
Technote (troubleshooting)
Problem(Abstract)
During insert from the CLP there is no codepage conversion if operating system codepage and database codepage are both UTF-8. In this case data to be inserted should also be in UTF-8 encoding.
If data has a different encoding then the database codepage (this can be verified using any hex editor), then the operating system codepage should be changed to match the data's encoding in order to enforce the data conversion to the database codepage.
Symptom
Error executing Select SQL statement. Caught by java.io.CharConversionException. ERRORCODE=-4220
Caused by: java.nio.charset.MalformedInputException: Input length = 4759 at com.ibm.db2.jcc.b.u.a(u.java:19) at com.ibm.db2.jcc.b.bc.a(bc.java:1762)
Cause
During an insert of data using CLP characters, they do not go through codepage conversion. If operating system and database codepage both are UTF-8, but the data to be inserted is not Unicode, then data in the database might have incorrect codepoints (not-Unicode) and the above error will be a result during data retrieval.
To verify the encoding for data to be inserted you can use any editor that shows hex representation of characters. Please verify the codepoints for non-ASCII characters that you try to insert. If you see only 1 byte per non-ASCII characters then you need to force the database conversion during insert from CLP to UTF-8 database.
To force codepage conversion during insert from the CLP make sure that the operating system codepage is non-Unicode and matching to the codepage of data when you insert data to Unicode database from non-Unicode data source.
Problem Details An example problem scenario is as follows:
- Create a database of type UTF-8:
CREATE DATABASE <db> USING CODESET utf-8 TERRITORY US - Create a table that holds character data:
CREATE TABLE test (col char(20)) - Check operating system locale:
locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" - Insert the non-ASCII characters 'Ã' , '³', '©' which have codepoint 0x'C3', 0x'B3',0x'A9' in codepage 819 into the table:
INSERT INTO test VALUES ('Ã') INSERT INTO test VALUES ('³') INSERT INTO test VALUES ('©') - By running the following statement, you can see that all INSERT statements caused only one byte to be inserted into the table:
SELECT col, HEX(col) FROM test
à C3 ³ B3 © A9
However, the UTF-8 representation of those characters are: 0x'C383' for 'Ã', 0x'C2B3' for '³', and 0x'C2A9' for '©'. So these three rows in the table contain invalid characters in UTF-8. - When selecting from a column using the JDBC application, the following error will occur. This is expected because the table contains invalid UTF-8 data: Error executing Select SQL statement. Caught by java.io.CharConversionException. ERRORCODE=-4220 Caused by: java.nio.charset.MalformedInputException: Input length = 4759 at com.ibm.db2.jcc.b.u.a(u.java:19) at com.ibm.db2.jcc.b.bc.a(bc.java:1762)
- Delete all rows with incorrect Unicode codepoints from the test table: DELETE * from test
- Change the locale to one that matching codepage of data to be inserted: export locale=en_us. One of the way to determine the codepage for your data can be found here: http://www.codeproject.com/Articles/17201/Detect-Encoding-for-In-and-Outgoing-Text. If you prepare data yourself using some editor please check the documentation for your editor to find out how to set up the codepage for data being prepared by the editor.
- Insert data to the table: INSERT INTO test VALUES ('Ã') INSERT INTO test VALUES ('³') INSERT INTO test VALUES ('©')
- Verify that inserted data were converted to UTF-8 during insert: SELECT col, HEX(col) FROM test
à C383 ³ C2B3 © C2A9 - Run your java application selecting Unicode data. No exception should be reported.
Environment
UNIX, Linux, Unicode database
Diagnosing the problem
Verify that non-ASCII data have a proper Unicode codepoints in Unicode database
Resolving the problem
Reinsert data with codepage conversion enforced by setting the operation system codepage matching to the codepage of data to be inserted
Related information
Community questions and discussion
By adding a comment, you accept our Terms of Use. Your comments entered on this IBM Support site do not represent the views or opinions of IBM. IBM, in its sole discretion, reserves the right to remove any comments from this site. IBM is not responsible for, and does not validate or confirm, the correctness or accuracy of any comments you post. IBM does not endorse any of your comments. All IBM comments are provided "AS IS" and are not warranted by IBM in any way.
Wrong codepoints for non-ASCII characters inserted in UTF-8 database using CLP的更多相关文章
- ascii、unicode、utf、gb等编码详解
很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的,于是他们把这称为"字节".再后来,他们又做了一些可以处理这 ...
- ASCII、UNICODE、UTF
在计算机中,一个字节对应8位,每位可以用0或1表示,因此一个字节可以表示256种情况. ascii 美国人用了一个字节中的后7位来表达他们常用的字符,最高位一直是0,这便是ascii码. 因此asci ...
- man ascii
Linux 2.6 - man page for ascii (linux section 7) - Unix & Linux Commands Linux 2.6 - man page fo ...
- ASCII Table/ASCII表
ASCII Table/ASCII表 参考: 1.Table of ASCII Characters
- ASCII 码对应表
Macron symbol ASCII CODE 238 : HTML entity : [ Home ][ español ] What is my IP address ? your public ...
- ASCII Art (English)
Conmajia, 2012 Updated on Feb. 18, 2018 What is ASCII art? It's graphic symbols formed by ASCII char ...
- ASCII Art ヾ(≧∇≦*)ゝ
Conmajia, 2012 Updated on Feb. 18, 2018 What is ASCII art? It's graphic symbols formed by ASCII char ...
- Ascii vs. Binary Files
Ascii vs. Binary Files Introduction Most people classify files in two categories: binary files and A ...
- [错误处理]UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)
Stackoverflow 回答: 将byte类型转化:byte_string.decode('utf-8') Jinja2 is using Unicode internally which mea ...
随机推荐
- 【电子基础】IIC总线工作原理
IIC总线工作原理 I2C总线进行数据传送时,时钟信号为高电平期间,数据线上的数据必须保持稳定,只有在时钟线上的信号为低电平期间,数据线上的高电平或低电平状态才允许变化. 起始和终止信号 :SCL线为 ...
- ThinkPad X220 完美黑苹果 Hackintosh OS X 10.11 El Capitan
原文链接:https://www.gaojinan.com/thinkpad-x220-hackintosh-osx-10-11-el-capitan-perfect.html //Update 20 ...
- Netty系列之Netty线程模型
Reference: http://www.infoq.com/cn/articles/netty-threading-model 1. 背景 1.1. Java线程模型的演进 1.1.1. 单线程 ...
- MySQL5.7 利用keepalived来实现mysql双主高可用方案的详细过程
Reference: http://blog.csdn.net/mchdba/article/details/51377989 服务器准备 Keepalived:192.168.13.15 Keep ...
- Oracle用户密码过期的处理方法
受影响版本:Oracle11g以上版本. 导致密码消失的原因:Oracle 11g中默认的DEFAULT概要文件中口令有效期PASSWORD_LIFE_TIME默认值为180天. 当以客户端登 ...
- C#学习笔记(3)——操作sqlserver数据库增删改查
说明(2017-5-25 16:29:35): 1. VS2010,视图->服务器资源管理器->数据连接->右键添加连接->服务器名(本机可以用点)->选择数据库-> ...
- 3. 支持向量机(SVM)拉格朗日对偶性(KKT)
1. 感知机原理(Perceptron) 2. 感知机(Perceptron)基本形式和对偶形式实现 3. 支持向量机(SVM)拉格朗日对偶性(KKT) 4. 支持向量机(SVM)原理 5. 支持向量 ...
- win8中的参数传递
列表页面: xaml: Gridview中的数据源是实体的集合: <i:EventToCommand Command="{Binding GridViewItemClick_Comma ...
- 【Unity】JsonUtility解析集合(collections)类型(List)
Unity自带的Json解析工具类JsonUtility居然没有API用于解析集合类型,也太鬼扯了吧. https://stackoverflow.com/questions/36239705/ser ...
- 【转】15个最受欢迎的Python开源框架
以下是伯乐在线从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框 ...