java同步mysql的数据到PostgreSQL时报错ERROR: invalid byte sequence for encoding "UTF8": 0x00

最近,同事在做一个功能,通过java程序将mysql中的一张表的数据同步到pgsql中,在同步过程中,插入到pgsql中出现了如下错误:
`### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
在位置:unnamed portal parameter $13

The error may involve com.absin.modules.shop.dao.UprodCollectionProductDao.insert-Inline

The error occurred while setting parameters

SQL: INSERT INTO uprod_collection_product ( "center_id", "create_uid", "write_uid", "name", "state", "manufacturer_code", "brand", "erp_category", "univ_category_id", "official_website_url", "specs", "futures", "remark", "is_trial", "molecular_weight_non_ab", "storage_condition", "price", "sales_discount_type", "cas_code", "specification_url", "dangerous_goods", "other_name", "references", "molecular_formula", "appearance", "solubility", "business_type", "proxy_area", "authorized_customer_type", "working_hours", "classify_id", "need_login", "supplier_name", "supplier_code", "laboratory_level", "root_code", "is_delete", "search_keywords", "create_date", "write_date", "absin_json_info" ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )

Cause: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00

在位置:unnamed portal parameter $13
; ERROR: invalid byte sequence for encoding "UTF8": 0x00
在位置:unnamed portal parameter $13; nested exception is org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
在位置:unnamed portal parameter $13`

和他一起通过查看一些资料,和咨询了公司的DBA定位到了问题,问题出现的原因是mysql的表中有些字段有转义字符 \0, 导致获取到数据后同步到pgsql中报错。
解决方法:在java中将从mysql中获取到的String类型的字段里的 \0 替换成 ""(空字符串):str.replaceAll("\0",""); 然后再插入到pgsql中。

posted @   一曲终两人遇  阅读(2148)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示