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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章