org.postgresql.util.PSQLException: Invalid character data was found.

java代码查询postgresql数据库出现报错如下:

org.postgresql.util.PSQLException: Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database.

尝试修改连接postgresql客户端编码,未能解决问题。

对于存在乱码的字段进行base64编码,可正常查询日志,查询结果后利用java对base64进行解码即可:

encode(vdata::bytea,'base64') as vdata //postgresql字段base64编码函数。

上述方法只能解决部分乱码造成的问题,并不能完全兼容乱码问题,暂未找到办法彻底解决,临时可通过sql语句根据一定的逻辑,过滤掉乱码数据。

你可能感兴趣的:(运维,postgresql,数据库,java)