This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 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. Thanks Srikanth
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.
Joined: Jun 19, 2000
Tieyi, 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 Srikanth