Solved for Mysql.
Mysql supports a socketFactory configuration property. I cloned the default and added proxy capabilities to it. Then the following worked in my applicationContext.xml:
<entry key="socksProxyHost" value="$" />
<entry key="socksProxyPort" value="$" />
A more general solution for any database would be nice.