SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220
Technote (troubleshooting)
Problem(Abstract)
When an application uses the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver) and is connected to a database with code set UTF-8 (code page 1208), it throws an SqlException with message including "Caught java.io.CharConversionException" and ERRORCODE=-4220 if the data in a character column that it queries contains a sequence of bytes that is not a valid UTF-8 string.
Symptom
An exception is thrown similar to this:
com.ibm.db2.jcc.am.SqlException: [jcc][t4][1065][12306][XXX.XXX.XXX] Caught java.io.CharConversionException. See attached Throwable for details. ERRORCODE=-4220, SQLSTATE=null [...] Caused by: java.nio.charset.MalformedInputException: Input length = XXX [...] Caused by: sun.io.MalformedInputException at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:XXX) [...]
Cause
The JCC driver throws the exception when data in a character column that it queries is not a valid string in the database code page.
The invalid data could have been input to the database in the following ways:
- By running an SQL statement which writes byte values to the database. For example:
INSERT INTO tab1 VALUES (X'C3')
- By running the IMPORT or LOAD commands for files which contain character data that is not in the code page of the client machine, so the appropriate code page conversion was not done. To make sure that the the appropriate code page conversion is done when running IMPORT or LOAD, specify the code page of the input file by including the
"codepage=x"
file type modifier (specifying the code page in place of x).
Diagnosing the problem
You can use the HEX function to find out what are the byte values in a character column.
For example, to find out the byte values in column COL1 in table TAB1, run: SELECT HEX(col1) FROM tab1
Resolving the problem
Update the invalid data with a valid UTF-8 character string.
Alternatively, for JCC driver versions that support it you can set the JCC configuration property db2.jcc.charsetDecoderEncoder=3 so that instead of throwing an exception the JCC driver returns the Unicode REPLACEMENT CHARACTER (U+FFFD) in place of a sequence of bytes that is not a valid UTF-8 string. The JCC configuration property db2.jcc.charsetDecoderEncoder is supported in versions of the JCC driver that come with DB2 LUW 9.5 Fix Pack 8 and later (APAR IC74896), DB2 LUW 9.7 Fix Pack 5 and later (APAR IC74895), and all DB2 LUW releases from DB2 10.1 onwards.
For example, suppose you have a Java program MyApp.java that executes an SQL query of a database column that contains a sequence of bytes that is not a valid string. When you run: java MyApp
it throws an exception. But when you run: java -Ddb2.jcc.charsetDecoderEncoder=3 MyApp
it returns the string with any invalid sequence of bytes replaced by the Unicode REPLACEMENT CHARACTER.
The Unicode REPLACEMENT CHARACTER often appears like this (a diamond with a question mark inside it) :
Related information
APAR IC78495 APAR IC74896 Making the setting for IBM Data Studio Making the setting for IBM Content Collector UDF to identify invalid data in a UTF-8 character colum How invalid data can get into a UTF-8 character column LOAD command IMPORT command HEX function
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.
SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220的更多相关文章
- (https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014550004)Topic: Caught java.io.CharConversionException. ERRORCODE=-4220, SQLSTATE=null
270002WDPN 3 Posts 0 people l ...
- 关于db2处理特殊字段出现异常java.io.charConversionException
记录一下以前遇到的问题 在使用db2数据库处理数据的时候,碰到特殊字段,出现的问题 java.io.charConversionException 官方解决方法: db2.jcc.charsetDec ...
- java.io.CharConversionException: Not an ISO 8859-1 character:
java.io.CharConversionException: Not an ISO 8859-1 character: XXX 这个问题可能是因为outputstream输出中文字造成的影响. r ...
- java.io.CharConversionException: Not an ISO 8859-1 character: [留]
笔记一下 问题代码如下: response.setContentType("text/html;charset=utf-8");ServletOutputStream out = ...
- 【代码笔记】Java文件的输入输出(1)——Java.io包的初步理解
Java里面文件的输入输出全部在java.io包里面. Java.io包里面所有的类都需要掌握. java.io包里面所有的东西都在上面了. 包里面的相关类.异常等树关系如下 类分层结构 java.l ...
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect 2014年06月29日 ...
- Mysql报错java.sql.SQLException:null,message from server:"Host '27,45,38,132' is not allowed to connect
Mysql报错java.sql.SQLException:null,message from server:"Host '27,45,38,132' is not allowed to co ...
- java.io.IOException: java.sql.SQLException: ORA-01502: index 'BTO.PK_xxxxx' or partition of such index is in unusable state
最近由于数据库的全备出问题了,所以一直在观察. 刚好发现很多不需要的数据,就删了几百个G的数据吧. 今天突然就报这个问题. java.io.IOException: java.sql.SQLExcep ...
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server"
java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to thi ...
随机推荐
- 网络广告CPS/CPC/CPV/CPM/CPA分别是什么意思
CPA:注册广告(一般按用户来计算)CPC:点击广告(一般按一千个ip计算)CPS:消费广告(用户通过你的网站中投放的广告,达成消费,有提成)CPM:展示广告(展示广告,一般的视频比较多)CPV:按照 ...
- SQL Server 2008 R2升级到SQL Server 2012 SP1
1.建议对生产环境对的数据库升级之前做好备份,以防不测. 2.从SQL Server 2008 R2 升级到SQL Server 2012 SP1,需要先安装SQL Server 2008 R2 的S ...
- LeetCode: Valid Palindrome 解题报告
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- python 中文编码(一)
我在学python的过程中,遇到的第二个问题,就是中文乱码,如今也算勉强入门了,在这里给大家说说我的经验,也算个新人引导吧. 在文章里,我会重点提到一个概念:有来有去. 即数据从哪里来,到哪里 ...
- 百度BAE使用ueditor 上传图片
研究BAE 也有一段时间了,但一直无法解决BAE 上传图片的问题. 在阅读了 http://blog.csdn.net/auver/article/details/10103789 和 http:// ...
- iOS高德地图使用-搜索,路径规划
项目中想加入地图功能,使用高德地图第三方,想要实现确定一个位置,搜索路线并且显示的方法.耗了一番功夫,总算实现了. 效果 WeChat_1462507820.jpeg 一.配置工作 1.申请key 访 ...
- mysql-connector-java-5.1.22下载
java连接mysql时,需要安装驱动.如果未安装,会出现找不到“com.mysql.jdbc.Driver”的错误. 最新版驱动是:mysql-connector-java-5.1.22 下载地址: ...
- shell常用命令大全
目录: 一.文件目录类命令 二.文件压缩和归档类命令 三.系统状态类命令 四.网络类命令 五.其他 一.文件目录类命令 1.查看联机帮助信息. man命令.#man ls info命令. #info ...
- PHP与Java进行通信的实现方法
缘起: 最近做了一个电商平台与网银整合的小东西,程序是开源的 Ecmall的,网银的接口也很规范,给出的文档很全,唯一的小问题是,网银使用的签名和验签的lib是只有java和c的,对java还熟悉一些 ...
- LibreOffice openoffice 区别
LibreOffice的初始版本号码被设置为与OpenOffice.org一致,故初始发布(2010年)即为第三版,并不存在第二版.第一版. 后来,甲骨文宣布停止OpenOffice.org的商业支持 ...