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 ...
随机推荐
- js模板引擎art-template使用方法
art-template是款性能卓越的 js 模板引擎 https://aui.github.io/art-template/ 特性 拥有接近 JavaScript 渲染极限的的性能 调试友好:语法. ...
- vs code 快捷键的使用
vs code 快捷键的使用 shift + f12 快速查找函数的生成Ctrl+F12 查看单个函数的定义Shift+F12 查看所有函数的定义ctrl + ` 是打开运行的程序ctrl + Tab ...
- 【转载】一个Sqrt函数引发的血案
转自:http://www.cnblogs.com/pkuoliver/archive/2010/10/06/sotry-about-sqrt.html 源码下载地址:http://diducoder ...
- DFI、DPI技术
废话: 因为xxoo的缘故接触到这个设备.但是就是单纯的去看并没有去研究它是个啥玩意.刚才无聊就百度科普了一波. DFI以及DPI简单通俗以自己的理解来将就是网络带宽的一种检测技术.既然是检测技术也就 ...
- RecyclerView 输出的和排版的不一样
遇到过这样一种情况,就是RecyclerView加载出来的和看到Android Studio里的不一样 原因是: @Override public ViewHolder onCreateViewHol ...
- java.io.ByteArrayOutputStream 源码分析
ByteArrayOutputStream 内部包含了一个缓冲区,缓冲区会随着数据的不断写入而自动增长,俗称内存流. 首先看一下俩个属性,buf是内部缓冲区,count是记录写入了多少个字节. pro ...
- Gojs简单例子
前台代码: <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> ...
- kindle书摘-活着-余华-活着不易,珍惜
https://github.com/starrtc/android-demo 中文版自序 标注(黄色) - 位置 29 作家的使命不是发泄,不是控诉或者揭露,他应该向人们展示高尚.这里所说的高尚不 ...
- CSS Notes
Margin vs. PaddingMargin is on the outside of block elements while padding is on the inside. Use mar ...
- python——读取MATLAB数据文件 *.mat
鉴于以后的目标主要是利用现有的Matlab数据(.mat或者.txt),主要考虑python导入Matlab数据的问题.以下代码可以解决python读取.mat文件的问题.主要使用sicpy.io即可 ...