Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing ResultSet from applet to Servlet and back...  RSS feed

 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I using the jr.jar package. From my signed applet i pass objects to the servlet and then back again with no problem. This includes an array of objects. But when i try to pass a result set i get

java.lang.ClassCastException

using the following code.

--Applet Code--

ResultSet rs = (ResultSet) HTTP.send( ConnServlet , ConnArray );

--Servlet Code--

ResultSet rs = stmt.executeQuery(dbquery);
Servlets.sendObjectToClient( resp , rs );

---end----


From my reading i understand that there is a better way to do this with Vectors? Could some one explain? or a Code example would be great.

Thanks All,
Brian
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's never a good idea to pass resultsets around. It's best to get the data out of them as quickly as possible and release them so that they can free their DB resources.

What data types you use to capture the data greatly depends upon the nature of the data you are reading. A column of Strings? Use a String array or List. Rows of complex data spanning mutliple columns? Perhaps a 2D Object array, or perhaps an array of beans that abstract the data collected.

Without more details on the nature of the data and how it is intended to be used, it's hard to say.
[ July 11, 2005: Message edited by: Bear Bibeault ]
 
Brian K Swingle
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear,
Thanks for answering. What i'm doing is using a signed applet along with javawebstart and jni to load a native .dll onto the users system read some system level specs. Then contact a servlet that will make the database connection for me and return the results for comparison with the users specs. There would be about 20 fields from a single database record to be compared. So you think maybe an array of Strings would be the best way to go?

Thanks,
Brian
 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings is probably what you can use, as they may contain all kinds of characters, and may contain [almost] unlimited amount of those.

Passing resultsets from applet to servlet wouldn't be of much sense, as ResultSet object is a database object, and is associated with connection and statement that produced it. Even if one manages to deserialize it, which itself may not work, if the drivers are different, calling methods on such a resultset will most likely result in database related exceptions, as the original connection is not available.

I would a bit disagree with Bear, as there are times when there is a good reason to keep resultset opened indefinetely, for example if a table is being read consequitively, and rescanning the table from top every time is too expensive.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!