This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Here's what you should do: First do all of your database processing, including even closing your resources. Use variables which keep track of what to do next, if you need them. (This is the "controller" part and as Bear says, it should go in a servlet.)