Make sure the sql you run can take advantage of table's indexes and make sure the right indexes have been defined.
Another thing to try if possible is to move the
java program as close (network-wise) as possible to the database, preferably on the same machine.
A good test to see if the sql that's the problem or the java program logic is to run the command via a different tool like powerbuilder or dbartisan and take note of the time.