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.
I have a Servlet that retrieves information from Database. It then stores the Resultset in the session and forward to another servlet. After that it closes the connection in the finally block. This seems to be working so far, I am not sure if this would always work, since the ResultSet is not Serializable. But I couldn't find a better way to pass around the information from one servlet to another (unless I process the data and store in a Set/Map). Does anybody has any experience with this? Thank you, Shobha
hi, I don't understand why result set needs to be serializable when u r forwarding the request to another servlet withing the same web app. It's better to store the result set in request scope and not session scope.
A good question ... as soon as you close the connection you are going to lose the ResultSet ... result sets are essentially a "view" of the data and rely on a connection. The solution is to marshall the data from the result into some Collection (as you stated). Another option would be to use a CachedRowSet or similar RowSet provided by JDBC 2.0 (if you can find a decent implementation).
Hi Shobha, As Bill said, resultset is invalid after the connection is closed. Also it is a good programming practice to iterate thro the result set as early as possible and copy data into set/map or some simple data holder classes with get/set methods, depending on your application and close connection. you can then pass the data holders around as your application logic says.