Connection Timeout problem ... solving try 1

    setMaxWait(-1) on the BasicDataSource. That tells it to wait
indefinitely for a connection.

    Check that the wait_timeout on your MySQL server is set to the
default 8h.

    Set ?autoReconnect=true on your JDBC URL

    setTestOnBorrow(true) on the BasicDataSource. This will prevent it
from handing out stale connections but will add overhead to your app
(though if you've already got such long single queries you probably
won't even notice that part).