File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes can result set be returned. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "can result set be returned." Watch "can result set be returned." New topic

can result set be returned.

Srinivas nellore

Joined: Oct 11, 2004
Posts: 2
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?

[ October 11, 2004: Message edited by: Srinivas nellore ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

Yes you can pass resultset, But you will have to keep your connection open until resultset is processed.

try using DTO or arraylist to return the values.

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Are you passing it across JVM's ?ResultSet is not Serializable.

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211


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
Sonny Gill LinkedIn
Nitin Dubey
Ranch Hand

Joined: Oct 30, 2000
Posts: 126


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.


Nitin Dubey
Srinivas nellore

Joined: Oct 11, 2004
Posts: 2
Many thanks.

It is working fine now.

Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 160
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 Here WEBlog
subject: can result set be returned.
It's not a secret anymore!