You have SQL / Business logic and presentation code all in one
servlet ? I would advise the following
1. Treat the servlet as a controller for the flow of code.
2. Create new service classes that will handle your business logic. Call them from the controller.
3. Move the data access logic to DAOs
4. Move the presentation logic to JSPs
I don;t have any idea about how to copy if there is no match
I am not quite sure what that means