I have a servlet through which I am calling a java bean. In the bean I am selecting the resultset. Now can how can pass this resultset back to servlet for doing further processing? I tried this but I am getting null as the returned value. Anyone tried this before?
As Sailesh indicated, it is a bad design to pass ResultSet back to the Servlet, you would be better of doing all ResultSet processing in the bean, storing the values that you need to pass in a data structure such as a List or a Map, release all database resources, and then pass that data structure back to the servlet.
The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny GillTweets
You can also go for the CachedRowSet implementations in the new JDBC APIs. This is the easiest of all. But you have to make sure that your product is running on a JDK that has these rowsets.
After you implemented Cacheing of your ResultSet either using some custom made structure or using an implementation of CachedRowSet make sure that you are not overloading your JVM by having enormous data stored in the cache. If so be ready for OutOfMemory Error or to avoid it go for increasing the JVM Heap through command line options.
Returning ResultSet to the Servlet is a bad design in 2 ways. 1 in processing the data and 2 in performance also, because you need to keep the connection live, till you process the data in the servlet.
so the best practice is to write a utility to execute your query/do database operations and return the result in a HashMap (this hashmap can be nested one also). and you can process this HashMap in your servlet/jsp as you need.
Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside HereWEBlog