[en] Solution to Postgres JDBC driver ignoring charSet directive with SQL_ASCII database

„New” Postgres JDBC drivers check database engine version and if it’s not below 7.3 they will ignore charSet declaration. It breaks encoding of 8-bit characters if database has SQL_ASCII encoding (which basically means DONT_CARE_ANYTHING_GOES). If your database is set to SQL_ASCII and in reality it stores e.g. Windows-1250 (CP1250) characters, JDBC driver will assume incorrect encoding and diacritical characters will be broken.

Even though I understand the reasons given by Postgres developers for this (SQL_ASCII is NOT supposed to be used with anything other than 7-bit characters and it is obsolete), the solution they’re suggesting (to dump the db, and convert it to UTF-8) is not always possible. For instance, I would have a hard time telling my customer to do it, especially because their old software might break.

So I’ve patched the JDBC driver to accept charSet directive in JDBC URLs and also added a method setCharset to PGSimpleDataSource.

Here you can download it: Postgres JDBC driver – charSet patched