I'm got a web application that has many
servlets for action processing and jsps for presentation. I also have some "helper"
java classes, one of which is a database class. In this class I have a method to get a
jdbc connection and many methods each running a certain sql statement and returning the resultSet.
Here is some process flow you'll need to help with the question. The user completes a form and it gets posted to a servlet. The servlet gets the parameters and calls a method from my database class. That method returns a ResultSet which I then set as an Attribute in session. Then I redirect the user back to another
jsp. I get the ResultSet from session and set it to a new ResultSet I instantiate (sp) in the jsp. After that I remove the resultset session attribute. Lastly I process through the ResultSet created in the jsp displaying the results of their search.
Now, what I need to do is close the jdbc connections properly. If I close the connection in the method within the database class I get errors about the connection already being closed and I'm getting a rull resultset. But since the connection object I use is a private variable I can only close it from the database class itself. Also, the connection object is a method variable for each method because I thought that if two people did the search at the same time and hit the database class together, they would be "updating" the same connection at the same time and it would cause problems. Am I wrong in thinking that?
Any help or direction is appreciated.
PS: I hope I didn't ramble too bad.