Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing ResultSet from servlet to applet

 
ifayyaz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a problem of passing ResultSet from servlet to applet.
Please let me know that if is it possible?
If yes then please tell me how?
Thanx in advance
Ahsan Fayyaz
 
paul wheaton
Trailboss
Pie
Posts: 21749
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about having a plain socket server (no HTTP involved)?
What about RMI?
Have these been ruled out?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual problem with this is that ResultSet is not Serializable. It can't be, as some of the data may retrieved on demand from the database. So you can't just serialize it and send it over to the client.
The usual solution is to loop through the ResultSet extracting the data and putting it into something that is Serializable, such as a Vector or a Hashtable. This is a fine solution provided you don't want to send a lot of data. If you need to send more (and you really can't filter it at the server end), then you may need to set up your own protocol or compression method.
Does any of this help?
 
ifayyaz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for replaying to me. I have tried the approach of converting the ResultSet to vector and then sending that back but it is very slow as i have thousands of records in DB. you have mentioned to use some personel protocol or so, how can i achive that?
Thanx a lot
Ahsan Fayyaz
------------------

Thanx in advance
Ahsan Fayyaz
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I thought this might be the case. My first question has to be: Do you really need to send "thousands" of records from a server to an applet? What will the applet do with them - I find it hard to imagine showing thousands of records on screen at one time.
If you can let me know what you are trying to do, what fields are contained in the records, and why you need all those records, we can sort out a strategy for making the communication more efficient.
I look forward to your reply.
 
ifayyaz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx again for getting out time for me. I am trying to actually show lets say employee names of different companies and thier company names.
what i wanted is that get the result set at servlet side and then pass it to applet so that after first time the gui should be efficient and should have less network traffic, but what i am getting from ur feed back is that i should call servlet from applet each time i wanna show new record.
won't that make too much traffic on network?
looking for ur reply

------------------

Thanx in advance
Ahsan Fayyaz
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's forget the data for a moment, and look at what the user wants to do with it. With thousands of possibilities, I guess a user is unlikely to want to step manually through all of them to look for something (I certainly wouldn't want to).
Presumably what a user would sometimes want to do is ask questions like: "how many people work for company A", or "which company does person X work for". In any cases like this the database should do the filtering using a "where" or "count" clause. In these cases the amount of data transmitted will be small.
Sometimes, I can imagine wanting to ask "who works for company A", but as with most web searches, you should probably consider sending back a page full (say the first 20 matches) and an indicator if there are any more to view. This gives the user a chance to back out without having to wait a long time if he enters the wrong company name by mistake or gets bored with lookimg through the list.
In this case I might expect to see a HTTP request something like
<pre>GET http://server/servlets/people?company=Microsoft&action=first</pre>;
followed by optional requests like
<pre>GET http://server/servlets/people?company=Microsoft&action=next</pre>;
to get the next page worth.
Each "first" request causes a "select name,etc from people where company='Microsoft'" to be sent to the database, and the first 20 (or all if there are less than 20) records to be sent to the client.
If you store your ResultSets in a Hashtable keyed by company name, then each "next" request just grabs the next few records from the ResultSet and sends it onward in a Vector (or whatever).
I'm sure your actual implementation will be different from this, but the things to bear in mind are:

  1. Allow the user to ask sensible, specific questions, don't just show them the whole lot at once.
  2. Do as much filtering in the database as you can. It's what it's best at.
  3. Allow for sending partial blocks of results, and leave the servlet in control of how large they are.
  4. Make the applet flexible so it will show however many the servlet sends, and allow the user to show more if required.
 
ifayyaz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx again for getting out so much time for me, i hope that i might go with your approach of sending data in blocks and i hope this will solve my problem.
i think it is fine with normal screen but what do suggest for reports where he can see the list of all employees or so by just scrolling the vertical scroll bar.
hope to hear from you soon

------------------

Thanx in advance
Ahsan Fayyaz
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,
I would like to know how to store data from Resultset to a vector or hashtable?Can anybody please tell me more about this.
Thanks,
Raju
 
paul wheaton
Trailboss
Pie
Posts: 21749
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently do the very thing you are asking about.
I have the servlet convert the data to something smaller and more manageable. Then I pipe it over an object stream.

 
John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Have you ever heard of "Model 2 design pattern" (A.K.A. "Servlet Dispatch Design Pattern") you can mimic the Model/View/Controller pattern and have your servlet (Controller) send the ResultSet from the Database (Model) to the Applet (View) by using the getServletcontext() static method and RequestDispatcher class.
This allows you to 'add' objects and info to the request method and then pass this object to a JSP or APPLET. Then your JSP/Applet can use the standard request.getParameter() [or whatever] method to access the information you just passed. This is accomplished without Sessions, RMI, CORBA, EJB or even Serialization of objects.
I assumed (possibly wrongly) that this was a comomon design patter, but I have seen many question on how to do this. I will gladly get into more details later this evening in a new thread.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic