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的更多相关文章

  1. (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 ...

  2. 关于db2处理特殊字段出现异常java.io.charConversionException

    记录一下以前遇到的问题 在使用db2数据库处理数据的时候,碰到特殊字段,出现的问题 java.io.charConversionException 官方解决方法: db2.jcc.charsetDec ...

  3. java.io.CharConversionException: Not an ISO 8859-1 character:

    java.io.CharConversionException: Not an ISO 8859-1 character: XXX 这个问题可能是因为outputstream输出中文字造成的影响. r ...

  4. java.io.CharConversionException: Not an ISO 8859-1 character: [留]

    笔记一下 问题代码如下: response.setContentType("text/html;charset=utf-8");ServletOutputStream out = ...

  5. 【代码笔记】Java文件的输入输出(1)——Java.io包的初步理解

    Java里面文件的输入输出全部在java.io包里面. Java.io包里面所有的类都需要掌握. java.io包里面所有的东西都在上面了. 包里面的相关类.异常等树关系如下 类分层结构 java.l ...

  6. 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日  ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【驱动】linux下I2C驱动架构全面分析

    I2C 概述 I2C是philips提出的外设总线. I2C只有两条线,一条串行数据线:SDA,一条是时钟线SCL ,使用SCL,SDA这两根信号线就实现了设备之间的数据交互,它方便了工程师的布线. ...

  2. .NET ramework 4.0安装失败

    1.停止Window 升级服务: 2.Windows 目录下的 SoftwareDistribution 重命名: 3.安装 .Net Framework 下面是百度上的方法,比较复杂 解决方法:1) ...

  3. 基于jQuery左侧大图右侧小图切换代码

    基于jQuery左侧大图右侧小图切换代码是一款带右侧缩略图选项卡的jQuery图片切换特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=" ...

  4. RecyclerView 输出的和排版的不一样

    遇到过这样一种情况,就是RecyclerView加载出来的和看到Android Studio里的不一样 原因是: @Override public ViewHolder onCreateViewHol ...

  5. Mac OS下 Redis2.6.14部署记录

    Mac OS下 Redis2.6.14部署记录 部署一个Redis作为缓存进行验证,记录部署过程. 官网:http://redis.io/,目前最近稳定版为2.6.14  解压,进入目录.按照READ ...

  6. js如何获取到本周的第一天和最后一天,本月的第一天和最后一天以及本季度的第一天和最后一天

    1.首先来一个自己公司项目的源码: 项目需求描述: 从20150712日开始, , 需求①:根据当前时间返回每一周 .周一~周日的日期(需返回2种格式 格式1:7月13日,格式2:2015-07-13 ...

  7. [uEnv.txt]在uEnv.txt文件中使用if语句实现Image/dtb文件切换

    指定image/dtb文件 bootdir= bootfile=zImage fdtfile=embest-SBCC_PH8800_WLQ.dtb loadaddr=0x82000000 fdtadd ...

  8. Introduction to MyBatis Generator Mybatis代码生成介绍

    Mybatis官方提供了代码生成工具,这里是官方网站: http://mybatis.github.io/generator/index.html 可以自动生成 Java POJOs, Mapper. ...

  9. Android——线程通讯类Handler(转)

    原文地址:http://uule.iteye.com/blog/1705951 handler是线程通讯工具类.用于传递消息.它有两个队列:1.消息队列2.线程队列 消息队列使用sendMessage ...

  10. 机器学习--详解人脸对齐算法SDM-LBF

    引自:http://blog.csdn.net/taily_duan/article/details/54584040 人脸对齐之SDM(Supervised Descent Method) 人脸对齐 ...