Try calling 'set global max_allowed_packet = 500 * 1024 * 1024' from the mysql command line (or whatever you wish your max to be). I've had this problem with MySQL in the past and was able to do this through the command line with success (you could do this on your machine be running the mysql command line tool and specify the appropriate host) - never tried it directly through JDBC but it might be worth trying (the user you login as needs to have permissions to change this global). If the large amount of data is from a single table column you are probably stuck with this option. Otherwise you might be able to piece up the query (say by looping over a limit clause) into subqueries which together get all the data.
You could have a script to do the query for you, but I don't see it as solving your initial problem.