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

New” Post­gres JDBC dri­vers check data­ba­se engi­ne ver­sion and if it’s not below 7.3 they will igno­re char­Set dec­la­ra­tion. It bre­aks enco­ding of 8‑bit cha­rac­ters if data­ba­se has SQL_ASCII enco­ding (which basi­cal­ly means DONT_CARE_ANYTHING_GOES). If your data­ba­se is set to SQL_ASCII and in reali­ty it sto­res e.g. Win­dows-1250 (CP1250) cha­rac­ters, JDBC dri­ver will assu­me incor­rect enco­ding and dia­cri­ti­cal cha­rac­ters will be broken.

Even tho­ugh I under­stand the reasons given by Post­gres deve­lo­pers for this (SQL_ASCII is NOT sup­po­sed to be used with any­thing other than 7‑bit cha­rac­ters and it is obso­le­te), the solu­tion they­’re sug­ge­sting (to dump the db, and convert it to UTF‑8) is not always possi­ble. For instan­ce, I would have a hard time tel­ling my custo­mer to do it, espe­cial­ly becau­se the­ir old softwa­re might break.

So I’ve pat­ched the JDBC dri­ver to accept char­Set direc­ti­ve in JDBC URLs and also added a method set­Char­set to PGSimpleDataSource.

Here you can down­lo­ad it: Post­gres JDBC dri­ver — char­Set patched