Postgres UTF-8 clobs with JDBC

2019-02-13 16:14发布

问题:

Postgres JDBC driver seems to not handle UTF-8 clobs correctly. When you retrieve the clob the characters are not correct (you get ? marks for non ascii characters).

Supposedly this is a known issue:

  • http://archives.postgresql.org/pgsql-bugs/2010-09/msg00034.php
  • https://jira.springsource.org/browse/SPR-7520
  • http://archives.postgresql.org/pgsql-jdbc/2011-02/msg00032.php

Luckily for my application I generally avoid clobs so the fields that were clobs I have just made into really big varchars.

How are other people dealing with this limitation?

回答1:

Adding @Type(type="org.hibernate.type.StringClobType") to the clob description in hibernate solves it for me.



回答2:

clob? You mean text or varchar, PostgreSQL doesn't have clob datatype. The PostgreSQL JDBC driver doesn't have problems with that, it would be useless without UTF8 support. It works fine over here.