I'm new to programming in
Java, so please forgive what might be a dumb question.
I wrote an application that makes many calls to a relational database. When I first wrote the program, I didn't take a lot of care to use code efficiently, and ended up repeating the same statements over and over throughout, making a single database connection to perform multiple select statements, and return multiple resultsets. And the thing ran like a champ.
But since I'm trying to go back and clean it up, I decided to move all the database calls to a separate class file (makes sense, I thought). Since the calls would use the same format, but use the resultsets differently, I decided to return the resultset back to the calling program, and scan it there. That works, however the processing speed fell massively. I have verified that I am closing the resultsets after every call (and subsequent processing of that resultset in the calling program). I think it's probably due to the fact that before, I was limiting the number of connection statements by having the db-logic inline with the main code, whereas now, every database call requires a new connection. Could that be the cause of the massive slowdown?
If that's so, can you suggest how I should organize the logic? Is it normal to isolate the database calls to a class of their own? Is it orthodox to return a resultset to the calling program, if the processing of the resultset differs for each statement performing the database lookup?
I'm just trying to write good code....
Thanks!