Meaningless Drivel is fun!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can result set be returned." Watch "can result set be returned." New topic
Author

can result set be returned.

Srinivas nellore
Greenhorn

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?

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

Joined: Aug 13, 2004
Posts: 1081

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: 8904

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


Groovy
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Srinivas,

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.

cheers
Sonny


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Nitin Dubey
Ranch Hand

Joined: Oct 30, 2000
Posts: 126

Shrinivas,

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.

Regards,


Nitin Dubey
Srinivas nellore
Greenhorn

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

It is working fine now.

Regards,
Srinivas
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 140
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can result set be returned.
 
Similar Threads
Count the Records
ava.lang.OutOfMemoryError: Java heap space
JSTL+Servlet+beans
Updateable ResultSet() not updating
org.springframework.beans.factory.BeanCreationException: Error creating bean with name...