It's not a secret anymore!
The moose likes Servlets and the fly likes JSP, Servlet & JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP, Servlet & JDBC" Watch "JSP, Servlet & JDBC" New topic

JSP, Servlet & JDBC

Srikanth Madduri

Joined: Jun 19, 2000
Posts: 10
Hi all,
I am trying to develop a project using JSP, Servlet and JDBC. The JSP gets the parameters from the User and passes to HttpServlet. The servlet validates and submits a query to the database using
Connection mycon = DriverManager.getConnection("jdbc dbc:mydb");
Statement mystmt = mycon.createStatement();
ResultSet rs = mystmt.executeQuery(sqlString);
Now the problem I am facing is to capture the contents of the the ResultSet and pass it to the client. I realised that ResultSet is not Serilaizable hence need to move it to a Vector object and then send to the client. But to send a huge Vector is not a very effective solution. It's ok to get a few(say 20) records at a time. But to print to the local printer, the whole resultset needs to be printed. So is it necessary to send the whole resultset to the client?
Could someone give more information on this, please. None of the tutorials seem to deal with this situation. Or am I doing something really unusual? Is there a better way to do this? Could you give me the code as well.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Will ResultSet.getBinaryStream() helps you in anyway...?
Tieyi Guo

Joined: Oct 29, 2001
Posts: 15
Hi there,
As I think, you should get the retrieved value out of the ResultSet anyway since you could not send it back to client directly. Then why do not you put the retrieved values together with their names into a session. For sure session object is passwd back and forth between the client and servlet. I am not sure how efficient it will be compared with sending a big vector by yourself, but I assume it will be a little bit better in both efficency and security.
Hope this helps.

Srikanth Madduri

Joined: Jun 19, 2000
Posts: 10
Thanks for giving valuable suggestion. I found that I had not understood the ResultSet correctly. A JSP can receive the ResultSet object from a Bean. The records in the ResultSet can be displayed on a JSP directly.
Thank all
mepurvi dholakia

Joined: May 28, 2003
Posts: 1
can you tell me how can a JSP receive the ResultSet object from a Bean ?
I agree. Here's the link:
subject: JSP, Servlet & JDBC
jQuery in Action, 3rd edition