Also see:http://archives.postgresql.org/pgsql-jdbc/2003-02/msg00042.php
I have not used the above patches yet, but plan to for those queries whose approximate size I do not know in advance.
-- Matt Mello