1. 同步到 PG
出现 invalid byte sequence for encoding "UTF8": 0x00
”
“invalid byte sequence for encoding "UTF8": 0x00”(注意:若不是 0x00
则很可能是字符集设置有误),是 PostgreSQL
独有的错误信息,直接原因是 varchar
型的字段或变量不接受含有 '\0'
(也即数值 0x00
、UTF
编码 '\u0000'
)的字符串 。官方给出的解决方法:事先去掉字符串中的 '\0'
,例如在 Java
代码中使用 str.replaceAll('\u0000', '')
,貌似这是目前唯一可行的方法。
具体方法:
// com.alibaba.datax.plugin.writer.postgresqlwriter.PostgresqlWriter.Task#commonRdbmsWriterSlave
this.commonRdbmsWriterSlave = new CommonRdbmsWriter.Task(DATABASE_TYPE){
@Override
public String calcValueHolder(String columnType){
...
}
@Override
protected PreparedStatement fillPreparedStatementColumnType(PreparedStatement preparedStatement, int columnIndex, int columnSqltype, String typeName, Column column) throws SQLException {
if (columnSqltype == Types.CHAR || columnSqltype == Types.VARCHAR) {
preparedStatement.setString(columnIndex + 1, column.asString().replaceAll("\u0000", ""));
return preparedStatement;
}
return super.fillPreparedStatementColumnType(preparedStatement, columnIndex, columnSqltype, typeName, column);
}
};
标签:u0000,常见问题,String,sequence,0x00,preparedStatement,DataX,解决,columnSqltype
From: https://www.cnblogs.com/kingron/p/18332913