DB2 选择字符问题

发布于 2024-12-12 00:37:34 字数 1249 浏览 0 评论 0 原文

我正在尝试从另一个人管理的 DB2 数据库中选择数据,以便将其插入到我管理的 SQL 数据库中进行数据操作。我正在使用 java 程序来执行此操作,并且该程序已在测试数据上成功测试。但是,由于 db2 数据中的奇怪符号,我收到错误。这是我的错误日志。

Incorrect string value: '\xC2\x97D #5...' for column 'Name' at row 1
java.sql.SQLException: Incorrect string value: '\xC2\x97D #5...' for column 'Name' at row 1
INSERT INTO `Temp_Equipment_Inventory`.`PC_Table10i` SET `Account_No`='1019TJ148001',`Inventory_No`='569931',`Building_No`='0060',`Location`='CLASSRM',`FYYR_No`='2004',`Cost`='635.00',`Name`='MICROPHONE LAVALIER WIRELESS  (ISCÂD #5290)                 SHURE MODEL ULXP14/85                                       ',`CDCATY`='   ',`CDSRCE`='M',`FLDCAL`=' ',`CDACQN`='G',`FLOWNR`='Y',`FLSHAR`=' ',`CDDELT`='00',`CNYTDT`='00',`NOPURO`='6870607-01 ',`NOPIMO`='01',`CDPREI`='E',`Original_Amount`='155.00',`Serial_Code`='0309040351          ',`CDCOMP`=' ',`NOCHECK`='680146 ',`CDCOMM`='3651400',`Last_Update`='2008-07-18',`CDDEPT`='148',`Room_No`='0300 ',`Date_Scanned`=NULL,`Date_Acquired`='2004-03-09',`Manufacturer_Name`='SHURE       ',`Expiry_Date`=NULL

正如您所看到的,“名称”列包含数据 (ISC·D #5290),并抛出有趣的错误。但是,当我浏览db2表中的数据时,这个并没有出现。

我已将 mysql 表设置为 UTF-8 unicode ci。

我无法编辑 db2 数据库,因为它不是由我管理的。

我还能做什么来尝试绕过数据中的这个符号?

I am trying to select data from a DB2 database managed by another person so I can insert it into my SQL database managed by me for data manipulation. I am using a java program to do this and the program has tested successfully on test data. However, I am getting errors because of strange symbols in the db2 data. Here is my error log.

Incorrect string value: '\xC2\x97D #5...' for column 'Name' at row 1
java.sql.SQLException: Incorrect string value: '\xC2\x97D #5...' for column 'Name' at row 1
INSERT INTO `Temp_Equipment_Inventory`.`PC_Table10i` SET `Account_No`='1019TJ148001',`Inventory_No`='569931',`Building_No`='0060',`Location`='CLASSRM',`FYYR_No`='2004',`Cost`='635.00',`Name`='MICROPHONE LAVALIER WIRELESS  (ISCÂD #5290)                 SHURE MODEL ULXP14/85                                       ',`CDCATY`='   ',`CDSRCE`='M',`FLDCAL`=' ',`CDACQN`='G',`FLOWNR`='Y',`FLSHAR`=' ',`CDDELT`='00',`CNYTDT`='00',`NOPURO`='6870607-01 ',`NOPIMO`='01',`CDPREI`='E',`Original_Amount`='155.00',`Serial_Code`='0309040351          ',`CDCOMP`=' ',`NOCHECK`='680146 ',`CDCOMM`='3651400',`Last_Update`='2008-07-18',`CDDEPT`='148',`Room_No`='0300 ',`Date_Scanned`=NULL,`Date_Acquired`='2004-03-09',`Manufacturer_Name`='SHURE       ',`Expiry_Date`=NULL

As you can see, the Name column has the data (ISCÂD #5290) with the funny  throwing the error. However, when I browse the data in the db2 table, this  does not appear.

I have set the mysql tables to UTF-8 unicode ci.

I cannot edit the db2 database since it is not managed by me.

What else can I do to try and get around this  symbol in my data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

桃气十足 2024-12-19 00:37:34

\xC2\x97 是用于编码 unicode 字符的 UTF-8 字节序列 - (破折号)

似乎 java 代码已将 UTF-8 数据转换为 UTF-16(本机 java 编码)而不对其进行解码。然后插入会失败,因为字符和破折号的 UTF-16 代码点实际上是无效的 UTF-8 代码点。

因此,也许解决方案是在执行插入之前使用 UTF-8 编解码器对 DB2 中读取的内容进行解码,以获得正确的 UTF-16 表示形式,或者如果目标数据库需要 UTF-8 编码,那么最好的解决方案可能不是完全通过 java.String 但只是读取和写入二进制数据。

\xC2\x97 is the UTF-8 byte sequence for encoding unicode character — (the em dash)

It seems like the java code has converted the UTF-8 data to UTF-16 (the native java encoding) without decoding it. Then the insert is failing because the UTF-16 code points for the characters  and em dash are actually invalid UTF-8 code points.

So perhaps the solution is to decode what is read in DB2 with the UTF-8 codec to obtain the proper UTF-16 representation before doing the insert, or if the target database requires UTF-8 encoding, then perhaps the best solution is not to go through java.String at all but just read and write binary data.

难忘№最初的完美 2024-12-19 00:37:34

我还能做什么来尝试绕过数据中的这个符号?

  1. 你的测试数据是什么?它是否针对 -cases 进行了测试?

  2. 制作类似数据库的虚拟副本或在出现问题的位置提取数据库样本。将字符替换为 \^A

我仍然相信问题出在您的 java 代码中,您没有正确解析事物。尝试用 Python 或更简单的 Java 代码来完成同样的事情。

What else can I do to try and get around this  symbol in my data?

  1. What is your test data? Is it tested for the  -cases?

  2. Make a dummy copy of a similar database or take a sample of the database at the location of the problem. Replace the character with \^A.

I still believe that the problem is in your java -code that you are not parsing things right. Try python or simpler code with Java to do the same thing.

醉梦枕江山 2024-12-19 00:37:34

如果您使用 UTF-8 进行编码,您可以尝试在 jdbc 连接 url 中添加以下参数

<connection_url>?useUnicode=yes&characterEncoding=UTF-8

。如果 UTF-8 不适合您的需求,您可以将其替换为您的编码。

希望有帮助。

If you 're using UTF-8 for the encoding you could try to add the following parameters in your jdbc connection url

<connection_url>?useUnicode=yes&characterEncoding=UTF-8

You could replace it with your encoding, if UTF-8 is not suitable for your needs.

Hope it helps.

赤濁 2024-12-19 00:37:34

跳过Java程序并使用DB提供的工具来移动数据。对于 DB2,请使用 db2 export 将数据导出到平面文件中。然后使用mysqlimport将其加载到MySql中。

Skip the Java program and use the DB provided tools to move the data. For DB2 use db2 export to get your data out into a flat file. Then use mysqlimport to load it into MySql.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文