This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can result set be returned.

 
Srinivas nellore
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you passing it across JVM's ?ResultSet is not Serializable.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nitin Dubey
Ranch Hand
Posts: 126
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks.

It is working fine now.

Regards,
Srinivas
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic