JDBC写入postgresql JSON格式数据类型出现错误

JDBC写入postgresql JSON格式数据类型出现错误

JDBC写入postgresql json格式出现以下错误:

Caused by: org.postgresql.util.PSQLException: ERROR: column "stu_json" is of type json but expression is of type character varying
  建议:You will need to rewrite or cast the expression.

解决方案:

在连接参数中加入:&stringtype=unspecified

用于把JSON类型当STRING类型存储

或者使用PGobject对象来传输

PGobject pgobject = new PGobject(); pgobject.setType("json"); pgobject.setValue(jsonString);