当前位置:网站首页>Exception of DB2 getting table information: caused by: com ibm. db2.jcc. am. SqlException: [jcc][t4][1065][12306][4.25.13]

Exception of DB2 getting table information: caused by: com ibm. db2.jcc. am. SqlException: [jcc][t4][1065][12306][4.25.13]

2022-07-07 07:02:00 Learn shameless realm

Problem description :

DB2 edition :DB2 v10.5.0.11
When JDBC adopt JCC drive (db2 drive ) Of DatabaseMetaData Medium getTables Get the database table information and throw an exception :

Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][t4][1065][12306][4.25.13]  Capture to  java.io.CharConversionException. For more information , See connected  Throwable. ERRORCODE=-4220, SQLSTATE=null
	at com.ibm.db2.jcc.am.b6.a(b6.java:794)
	at com.ibm.db2.jcc.am.b6.a(b6.java:66)
	at com.ibm.db2.jcc.am.b6.a(b6.java:125)
	at com.ibm.db2.jcc.am.bh.a(bh.java:2963)
	at com.ibm.db2.jcc.am.bh.p(bh.java:575)
	at com.ibm.db2.jcc.am.bh.P(bh.java:1656)
	at com.ibm.db2.jcc.am.ResultSet.getStringX(ResultSet.java:1225)
	at com.ibm.db2.jcc.am.ResultSet.getString(ResultSet.java:1194)
	at com.ibm.db2.jcc.am.ResultSet.getString(ResultSet.java:1787)
	at com.geominfo.bi.meta.crawler.AbstractMetaCrawler.getTableAndRemarks(AbstractMetaCrawler.java:539)
	... 80 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
	at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
	at com.ibm.db2.jcc.am.x.a(x.java:52)
	at com.ibm.db2.jcc.am.bh.a(bh.java:2952)
	... 86 common frames omitted

reason

When JCC When the data in the character column queried by the driver is not a valid string in the database code page ,JCC The driver will throw an exception .

Invalid data may have been entered into the database in the following ways :
Write byte values to the database by running SQL sentence . for example :INSERT INTO tab1 VALUES (X’C3’)
By running IMPORT or LOAD command , Therefore, the corresponding code page conversion was not performed . To ensure that it is running IMPORT or LOAD Complete the corresponding code page conversion , Please include the file type modifier ( Specify a code page instead x) To specify the code page of the input file .“codepage=x”

Diagnosis problem

You can use hexadecimal functions to find byte values in character columns .
for example , To find the table TAB1 in COL1 Byte value in column , Please run :
SELECT HEX(col1) FROM tab1

solve the problem

Use effective UTF-8 String update invalid data .

perhaps , For those who support it JCC Driver version , You can set JCC Configuration properties db2.jcc.charsetDecoderEncoder=3, In order to JCC The driver does not throw an exception , It's going back to Unicode Replace character (U+FFFD) Substitution is not effective UTF-8 Byte sequence of string .
JCC Configuration properties db2.jcc.charsetDecoderEncoder stay DB2 LUW 9.5 FP8 And higher (APAR IC74896)、DB2 LUW 9.7 FP 5 And higher (APAR IC74895) And from DB2 10.1 All that started DB2 LUW Supported in distribution .

for example , Suppose you have a Java Program MyApp.java It performs SQL Inquire about , The database column contains a byte sequence that is not a valid string .
Runtime :

It throws an exception . But when you run :

The string it returns contains any invalid byte sequence , These byte sequences are Unicode Replace character replace .

Unicode Replacement characters are usually as follows

java -Dfile.encoding=gb18030 -Ddb2.jcc.charsetDecoderEncoder=3 -jar MyApp.jar

Reference material :
https://www.itdaan.com/blog/2015/05/09/3f8fc9857f8b3de1669d63b3abaad6f1.html
https://www.ibm.com/support/pages/sqlexception-message-caught-javaiocharconversionexception-and-errorcode-4220
https://www.it1352.com/2818869.html
https://www.cnblogs.com/lpzpp/p/13986533.html

原网站

版权声明
本文为[Learn shameless realm]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070219047971.html